HTTP proxy — veilgate-proxy
A framework-agnostic redaction gateway plus a dependency-free Node HTTP handler. Redacts outbound, re-hydrates the reply, blocks fail-closed, and caps request bodies.
veilgate-proxy wraps the core engine into a gateway you can put in front of
any cloud model. 10 tests.
npm install veilgate-proxyrunGateway(payload, options)
Framework-agnostic. It redacts the payload, calls your forward handler with the redacted
text, re-hydrates the reply, and throws GatewayBlockedError instead of forwarding a BLOCK.
import { runGateway, GatewayBlockedError } from "veilgate-proxy";
try {
const result = await runGateway("My name is Alice Johnson.", {
forward: async (redacted) => callCloudModel(redacted), // only ever sees placeholders
reroute: async (original) => callLocalModel(original), // trusted on-prem path
});
result.text; // re-hydrated reply
result.status; // "forwarded" | "rerouted"
} catch (err) {
if (err instanceof GatewayBlockedError) {
// a BLOCK decision — nothing was forwarded
}
}If a span wants REROUTE_LOCAL but no reroute handler is provided, the gateway throws rather
than silently forwarding the original to the cloud. A BLOCK always throws. The safe default is
to refuse, never to leak.
createHttpHandler(options)
Wraps runGateway into a dependency-free Node http request handler:
import { createServer } from "node:http";
import { createHttpHandler } from "veilgate-proxy";
const handler = createHttpHandler({
forward: async (redacted) => callCloudModel(redacted),
reroute: async (original) => callLocalModel(original),
policy, // optional: any Policy
maxBodyBytes, // optional: request body cap (default 1 MiB)
});
createServer(handler).listen(8787);The POST body is the payload — a JSON string, a JSON object, or a chat array.
| Response | Meaning |
|---|---|
200 + { status: "forwarded", text } |
Redacted, forwarded, reply re-hydrated |
200 + { status: "rerouted", text } |
Diverted to the local handler |
403 + { status: "policy_block", reason } |
A BLOCK decision — the model was never called |
413 |
Request body exceeded maxBodyBytes |
This is exactly what the repo’s pnpm serve example runs — start it and curl it to watch the
model receive only placeholders.