Mock vs. live mode
Veilgate runs deterministically in mock mode with no API key, and calls the real Jev API in live mode. How to switch, supply the key, inject your own client, and why regex always runs first.
redact() runs in one of two modes, set with options.mode. Mock is the default.
| Mock (default) | Live | |
|---|---|---|
| Network | None | Calls the Jev API |
| API key | Not needed | Needed only when Veilgate builds the client |
| Determinism | Fully deterministic fixtures | Model-driven |
| Use for | CI, local dev, demos, tests | Production |
Which should I use? Stay in mock mode for local dev, tests and CI — it needs nothing. For
production, use live mode and inject your own Jev client: you
build and authenticate it, Veilgate just calls it. The quickest way to try live mode is to let
Veilgate build the client from your TYPESAFE_API_KEY — but that built-in path is still unverified
against the real SDK, so it’s for experimentation, not production.
Mock mode
Jev evaluations come from deterministic fixtures, so the same input always produces the same decisions — ideal for tests, CI and local development. No network, no API key.
await redact("My name is Alice Johnson."); // mock by default
await redact("My name is Alice Johnson.", { mode: "mock" });Live mode
Switch with mode: "live" and Veilgate calls the real Jev API. To do that it needs a Jev
client — the object with a systemOne() method — and it gets one of two ways:
- Veilgate builds the client for you (default) — just pass
mode: "live"; it constructs the SDK client internally and reads your API key then. See Supplying the API key. - You inject your own client through
options.client— recommended for production. See Injecting your own client.
await redact(text, { mode: "live" }); // Veilgate builds the client; reads TYPESAFE_API_KEY
await redact(text, { mode: "live", jev: { apiKey } }); // …with the key passed explicitly instead
await redact(text, { mode: "live", client: myJevClient }); // …or inject your own clientTune the built-in adapter through options.jev (a Partial<JevConfig>):
await redact(text, {
mode: "live",
jev: {
model: "jev-1.13.0",
baseUrl: "https://api.typesafe.ai",
maxTokensPerCall: 6000,
inputPricePerMTok: 0.042,
},
});Supplying the API key
This applies only when Veilgate builds the client for you. If you inject your own client, or run in mock mode, no key is read at all — mock never even imports the SDK.
When Veilgate constructs the client it resolves the key once, in this order:
options.jev.apiKey— an explicit key passed on the call.- The
TYPESAFE_API_KEYenvironment variable — read automatically whenjev.apiKeyis omitted.
redact() is stateless, but you don’t repeat the key on every call: set TYPESAFE_API_KEY once
in the environment and every live call reads it. Pass jev.apiKey only when you need a different key
per call. The key is used solely as the SDK client’s credential — it is never part of the payload
sent to Jev (the post-regex state and the questions), and it is never logged.
Putting the key in the environment
Never hardcode it. The repo ships a .env.example documenting the variable:
# local dev — copy the template and fill it in
cp .env.example .env
# .env → TYPESAFE_API_KEY=your-key-here
# …or export it for the current shell
export TYPESAFE_API_KEY=your-key-hereIn production, set TYPESAFE_API_KEY wherever your host manages secrets — your platform’s
environment settings (Vercel, Fly, Railway, a container env var) or your orchestrator’s secret store.
Veilgate reads TYPESAFE_API_KEY from process.env directly; it does not parse .env files. A
.env only works once something loads it into the environment — run with node --env-file=.env, add
import "dotenv/config", or use a framework that auto-loads it (Next.js does; plain Node does not).
So put the key in the environment and make sure it’s loaded before redact() runs. .env is
gitignored — never commit a real key.
Injecting your own client
The built-in client wrapper around @typesafe-ai/sdk is the one part still unverified against
the real SDK types. Mock mode and an injected client are fully exercised and tested, so for
production today, inject your own verified client. See the roadmap.
You give options.client any object with a systemOne() method. Its contract:
- Input:
{ model, state, questions }.stateis the post-regex payload; eachquestionis{ key, kind: "noul" | "score", prompt }. - Output:
{ answers }— a flat map keyed by eachquestion.keywith its probability.
Construct and authenticate the SDK client once (the key lives inside it), then map that contract onto
it. This mirrors Veilgate’s own built-in wrapper, so it’s a good starting point — verify the SDK
import names and request/response shape against the installed @typesafe-ai/sdk:
import { redact } from "veilgate";
import { TypeSafe, noul, score } from "@typesafe-ai/sdk";
// Build it once — the key stays inside this client, not in redact() calls.
const jev = new TypeSafe({ apiKey: process.env.TYPESAFE_API_KEY });
const client = {
systemOne: async ({ model, state, questions }) => {
const res = await jev.systemOne({
model,
state,
questions: questions.map((q) =>
q.kind === "noul" ? noul(q.key, q.prompt) : score(q.key, q.prompt),
),
});
return { answers: res.answers }; // { [question.key]: probability }
},
};
await redact(text, { mode: "live", client }); // reuse across calls; no key passed to redact()The test suite injects a stub of the same shape — returning fixed answers — which is how live-mode
behaviour is tested without a network.
Regex runs first, in both modes
The deterministic regex fast-path runs before Jev regardless of mode. In live mode, Jev is sent only the post-regex payload — a regex-stripped secret is never leaked into Jev’s ambient state. This is covered by a regression test.