maskyr documentation
maskyr runs on 127.0.0.1:8787 as a local egress gateway between your applications and upstream AI providers. Deterministic validators, context cues, heuristics, and a name gazetteer detect sensitive entities on your host, substitute format-preserving pseudonyms backed by an encrypted vault, and restore original values when responses return.
Documentation contents
Quickstart
maskyr requires Node.js 24 or newer (with zero external runtime dependencies) and stores state inside MASKYR_HOME (defaulting to ~/.config/maskyr). Initialize the vault and default configuration once, then start the loopback proxy on 127.0.0.1:8787.
# Optional: store config, vault, and audit log in a custom directory
export MASKYR_HOME="$HOME/.config/maskyr"
# Create config.json and encrypted maskyr.vault (keyfile mode by default)
node bin/maskyr.mjs init
# Or prompt for a passphrase (minimum 10 characters, scrypt KDF)
node bin/maskyr.mjs init --passphrase
# Start the local gateway on http://127.0.0.1:8787
node bin/maskyr.mjs start
When node bin/maskyr.mjs start runs in keyfile mode, it decrypts maskyr.vault automatically using the mode-0600 key file. Passphrase-mode vaults stay locked until you supply MASKYR_PASSPHRASE at startup or authenticate in the local UI at http://127.0.0.1:8787/.
Essential CLI commands
| Command | Purpose |
|---|---|
node bin/maskyr.mjs init [--passphrase] |
Create config.json and encrypted maskyr.vault (keyfile mode by default). |
node bin/maskyr.mjs start [--port N] [--host H] |
Run the gateway on 127.0.0.1:8787 until SIGINT or SIGTERM. |
node bin/maskyr.mjs scan [FILE|-] [--json] [--show] |
Detect sensitive spans without a vault; exits 1 if the balanced policy would mask or block anything. |
node bin/maskyr.mjs mask [FILE|-] [--scope ID] |
Mask text with the active policy and write mappings to the vault (refuses while a gateway is running). |
node bin/maskyr.mjs restore [FILE|-] [--scope ID] |
Restore original values from pseudonyms stored in the specified vault scope. |
node bin/maskyr.mjs wrap [--url URL] -- <command> [args...] |
Run a child command with OPENAI_BASE_URL and OPENAI_API_BASE pointing at an ephemeral or running gateway (OpenAI-compatible clients only; native Anthropic and Gemini SDKs are not covered). |
node bin/maskyr.mjs doctor |
Run read-only checks on Node version, config permissions, vault status, port availability, key sources, and local backend reachability. |
node bin/maskyr.mjs vault status|lock|export FILE|purge |
Inspect vault status, lock in-memory keys, export the encrypted vault file, or purge stale scopes. |
node bin/maskyr.mjs service print|install|uninstall |
Print or manage a Linux systemd user unit (--dry-run previews without installing). |
Non-loopback binding guard: maskyr binds to 127.0.0.1 by default. Passing a non-loopback --host requires MASKYR_GATEWAY_TOKEN, and clients must send it in the x-maskyr-token header.
SDK and provider routing
maskyr implements POST /v1/chat/completions (plain JSON and SSE streaming), GET /v1/models, and GET /healthz. Requests to /v1/messages, /v1/responses, and /v1/embeddings return HTTP 501 because only chat completions is protected by the masking pipeline. Native Anthropic and Gemini SDKs do not connect directly: call Claude and Gemini models through an OpenAI-compatible SDK targeting http://127.0.0.1:8787/v1 with anthropic/... (or claude-*) or gemini/... (or gemini-*) model names.
registry.resolve() routes outbound requests in order by providerId/model prefix, exact match in providers[].models, family prefix (gpt-*/o1/o3/o4, claude-*, gemini-*), or defaultProvider (openai).
Point any OpenAI SDK client at http://127.0.0.1:8787/v1. By default, the openai provider enables passthroughAuth: true, so your client Bearer key or OPENAI_API_KEY on the gateway host authenticates upstream.
export OPENAI_BASE_URL="http://127.0.0.1:8787/v1"
export OPENAI_API_KEY="sk-..."
curl http://127.0.0.1:8787/v1/chat/completions \
-H "content-type: application/json" \
-H "authorization: Bearer $OPENAI_API_KEY" \
-H "x-maskyr-scope: ticket-4102" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [
{ "role": "user", "content": "Draft a follow-up for John Martin at john.martin@example.org." }
]
}'
Native Anthropic SDKs and /v1/messages are not supported (calling /v1/messages returns HTTP 501). Instead, use an OpenAI-compatible SDK pointed at http://127.0.0.1:8787/v1 with a claude-* or anthropic/<model> identifier. maskyr translates messages, tools, and SSE streams to Anthropic's upstream /v1/messages API using ANTHROPIC_API_KEY on the gateway host or vault secret provider:anthropic (passthroughAuth defaults to false).
# On the gateway host (or stored via POST /admin/api/providers/anthropic/key)
export ANTHROPIC_API_KEY="sk-ant-..."
# Client targets OpenAI-compatible /v1/chat/completions
curl http://127.0.0.1:8787/v1/chat/completions \
-H "content-type: application/json" \
-H "x-maskyr-scope: review-88" \
-d '{
"model": "anthropic/claude-sonnet-4-20250514",
"messages": [
{ "role": "user", "content": "Summarize the contract sent by Clara Nordin." }
]
}'
Call Gemini models through an OpenAI-compatible SDK targeting http://127.0.0.1:8787/v1 with a gemini/<model> or gemini-* model name (native Gemini SDKs are not supported). maskyr calls generateContent or streamGenerateContent upstream and passes GEMINI_API_KEY (or vault secret provider:gemini) exclusively in the x-goog-api-key header, never in the URL query string (passthroughAuth defaults to false).
# On the gateway host (or stored via POST /admin/api/providers/gemini/key)
export GEMINI_API_KEY="AIza..."
# Client targets OpenAI-compatible /v1/chat/completions
curl http://127.0.0.1:8787/v1/chat/completions \
-H "content-type: application/json" \
-d '{
"model": "gemini/gemini-2.5-flash",
"messages": [
{ "role": "user", "content": "Verify IBAN DE89370400440532013000 formatting." }
]
}'
registry.resolve() routes only across configured providers[]: sending "model": "local" hits defaultProvider (openai) unless explicitly defined in providers. Actual local execution happens through config.local (none, openai-compatible, or the deterministic development fixture stand-in) when an active policy sets a matched entity kind's action to local or enables non-streaming routing.localFallback: true. assertLocalUrl restricts baseUrl to loopback or private network ranges, and local backends receive unmasked originals on-host.
// Inside $MASKYR_HOME/config.json
{
"local": {
"type": "openai-compatible",
"baseUrl": "http://127.0.0.1:11434/v1",
"model": "llama3.1:8b"
},
"policies": {
"balanced": {
"kinds": { "ssn": "local" },
"routing": { "localFallback": true }
}
}
}
For Node.js applications (Node 24 or newer), import the helper directly from src/sdk/index.ts. createMaskyr() exposes openaiConfig(), chat(), and chatStream(), while blocked(err) distinguishes maskyr_blocked refusals (where sent: false) from upstream provider errors.
import { createMaskyr, blocked } from '/path/to/maskyr/src/sdk/index.ts';
const mk = createMaskyr({ baseUrl: 'http://127.0.0.1:8787', scope: 'thread-42' });
try {
const reply = await mk.chat({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'Reply to John Martin (john.martin@example.org).' }],
});
console.log(reply.choices[0].message.content);
} catch (err) {
if (blocked(err)) console.error('Blocked locally:', err.code, err.sent);
else throw err;
}
Configuration schema
maskyr reads $MASKYR_HOME/config.json at startup and persists updates made through the Admin API with file mode 0600. Secrets are never written to config.json: provider API keys reside in environment variables or inside the encrypted vault.
{
"listen": { "host": "127.0.0.1", "port": 8787 },
"providers": [
{
"id": "openai",
"type": "openai",
"baseUrl": "https://api.openai.com/v1",
"apiKeyEnv": "OPENAI_API_KEY",
"passthroughAuth": true
},
{
"id": "anthropic",
"type": "anthropic",
"baseUrl": "https://api.anthropic.com",
"apiKeyEnv": "ANTHROPIC_API_KEY",
"passthroughAuth": false
},
{
"id": "gemini",
"type": "gemini",
"baseUrl": "https://generativelanguage.googleapis.com/v1beta",
"apiKeyEnv": "GEMINI_API_KEY",
"passthroughAuth": false
}
],
"defaultProvider": "openai",
"activePolicyId": "balanced",
"policies": { /* balanced, strict, permissive, plus custom policies */ },
"local": { "type": "none" },
"corsOrigins": [],
"maxBodyBytes": 8388608
}
| Top-level key | Default | Behavior |
|---|---|---|
listen |
127.0.0.1:8787 |
Gateway bind host and port. Host header validation prevents DNS rebinding. |
vaultPath |
$MASKYR_HOME/maskyr.vault |
Path to the AES-256-GCM encrypted vault file. loadConfig() does not expand ~: omit vaultPath to use the default or supply an absolute path such as /home/user/.config/maskyr/maskyr.vault. |
providers |
openai, anthropic, gemini |
Upstream adapter definitions across the four upstream types (openai, anthropic, gemini, openai-compatible). |
activePolicyId |
"balanced" |
Selects the active key from policies for outbound inspection and masking. |
policies |
Built-in presets | Map of policy objects normalized via normalisePolicy() on load or update. |
local |
{ "type": "none" } |
Local backend configuration (none, openai-compatible, or the deterministic development fixture stand-in, not an AI model). Optional baseUrl, model, and detectionModel configure an external loopback OpenAI-compatible server. |
corsOrigins |
[] |
Browser origins permitted to call /v1 and /healthz. Admin routes never emit CORS headers. |
maxBodyBytes |
8388608 (8 MiB) |
Upper bound on request body size accepted by both /v1/chat/completions and /admin/api/chat. |
Entity kinds and policies
Every detected span is classified into one of 20 EntityKind categories defined in src/types.ts. Detection runs deterministically on your host via regex validators, context cues, title-case and address heuristics, a static name gazetteer, and policy allow/deny terms. Each policy assigns an action (mask, block, allow, or local) per kind, plus confidence thresholds and residual leak handling.
Fylume detection model status: Fylume's specialised local detection model is currently in development and is not yet bundled in this repository. policy.modelDetection.enabled defaults to false (with onFailure: "block"). You can optionally point config.local at an external loopback OpenAI-compatible server, which is also disabled by default (type: "none").
Kind actions
mask Replace with a format-preserving pseudonym and restore in responses.
block Refuse the request before egress (policy-block-kind).
allow Leave the value intact without masking.
local Route the unmasked request exclusively to the local backend.
Policy guardrails
Confidence floor: minConfidence is 0.6 (balanced), 0.4 (strict), and 0.8 (permissive).
Residual scan: onResidual defaults to "block" in balanced/strict and "warn" in permissive.
DOB shifting: preserve.shiftDob shifts dates of birth by a deterministic per-scope offset so age intervals hold.
Term lists: allowTerms bypass masking; denyTerms always mask as custom.
| EntityKind | Description | Balanced | Strict | Permissive |
|---|---|---|---|---|
person |
Personal names and honorific-prefixed names | mask | mask | mask |
org |
Companies, institutions, and named organizations | mask | mask | allow |
email |
Email addresses | mask | mask | mask |
phone |
International and national telephone numbers | mask | mask | mask |
address |
Street addresses and postal lines | mask | mask | mask |
location |
Cities, regions, and geographic places | allow | mask | allow |
national_id |
National identity numbers (contextual and rule-based) | mask | mask | mask |
ssn |
Social Security numbers | mask | block | mask |
tax_id |
Taxpayer and VAT identifiers | mask | mask | mask |
business_id |
Company registration and enterprise numbers | mask | mask | mask |
passport |
Passport document numbers | mask | mask | mask |
id |
Generic labeled identifiers | mask | mask | mask |
iban |
International Bank Account Numbers (checksum-validated) | mask | mask | mask |
bank_account |
Domestic bank account and routing numbers | mask | mask | mask |
card |
Payment card numbers (Luhn-validated) | mask | block | mask |
dob |
Dates of birth (supports consistent shiftDob) |
mask | mask | mask |
ip |
IPv4 and IPv6 network addresses | mask | mask | allow |
url |
HTTP, HTTPS, and FTP URLs (http://, https://, ftp://) |
mask | mask | allow |
secret |
API keys, private keys, bearer tokens, credentials | block | block | block |
custom |
Manual preview terms and policy denyTerms |
mask | mask | mask |
Built-in policies also govern attachments and tool calls: images and binary files are blocked by default (images: "block", otherFiles: "block"), text files are decoded and masked (textFiles: "mask"), and toolCalls.restore defaults to "allowlist" with an empty list in balanced, "none" in strict, and "all" in permissive.
Encrypted vault and aliases
Original-to-pseudonym mappings and stored provider API keys sit inside maskyr.vault, an AES-256-GCM encrypted JSON envelope written atomically with 0600 permissions and a fresh initialization vector on every save. The envelope header is authenticated as additional associated data (AAD), and HKDF-SHA256 derives separate encryption (vault/enc) and deterministic pseudonym seeding (vault/pseudonym) subkeys.
Keyfile vs passphrase mode
Keyfile: Default for node bin/maskyr.mjs init. Generates a 32-byte .key file (permissions 0600) alongside the vault so node bin/maskyr.mjs start opens the store automatically for headless services.
Passphrase: Enabled with node bin/maskyr.mjs init --passphrase. Derives the master key with scrypt (N=32768, r=8, p=1) and requires MASKYR_PASSPHRASE or POST /admin/api/vault/unlock.
Conversation vs global scope
Per-thread isolation: Derives a deterministic identifier from the opening messages (or accepts an explicit x-maskyr-scope header) so external providers cannot correlate pseudonyms across threads.
Shared store: Setting scope: "global" keeps one mapping table across requests so recurring names resolve to the same pseudonyms everywhere.
Multi-token alias restoration
Individual word segments (excluding honorifics and tokens shorter than three characters) map independently alongside full names so partial references stay aligned across requests and replies:
During restoration, maskyr guards against exfiltration links: any pseudonym embedded inside a URL token or a markdown link target is left un-restored (recorded in maskyr.urlGuarded). For SSE streams, StreamRestorer holds back trailing text that could still complete a known pseudonym so split tokens are restored whole.
Local gateway control
Management routes listen at http://127.0.0.1:8787/admin/api, require the per-start secret from $MASKYR_HOME/admin.token in x-maskyr-admin, reject cross-origin calls, and omit CORS headers.
| Endpoint | Behavior |
|---|---|
POST /admin/api/preview[?reveal=1] |
Dry-run masking using the active policy and vault without persisting new mappings or sending network traffic. Returns { masked, spans, blocked, residual, route }; pass ?reveal=1 to include original span text. |
POST /admin/api/chat |
Executes the full /v1/chat/completions pipeline with keepInspection: true (respecting config.maxBodyBytes) and returns x-maskyr-request-id for payload inspection. |
GET /admin/api/transmissions/:id[?reveal=1] |
Reads the masked outbound payload and span offsets from the in-memory ring (last 20 requests, cleared when the vault locks). Pass ?reveal=1 to inspect original text and span originals. |
GET /admin/api/vault/scopes/:id[?reveal=1] |
Lists entries for a vault scope; original values and aliases stay null unless ?reveal=1 is passed. |
GET /admin/api/state |
Returns gateway listen config, vault status and key mode, active policy, provider key sources (never secrets), and local backend health. |
GET /admin/api/audit |
Returns metadata-only AuditRecord entries (counts, route, duration, residual findings) without originals or pseudonyms. |
GET /admin/api/vault/export |
Downloads the encrypted maskyr-vault-backup.json envelope as application/octet-stream. |
ADMIN_TOKEN=$(cat "${MASKYR_HOME:-$HOME/.config/maskyr}/admin.token")
curl -s http://127.0.0.1:8787/admin/api/preview \
-H "content-type: application/json" \
-H "x-maskyr-admin: $ADMIN_TOKEN" \
-d '{"text":"Send invoice to John Martin at john.martin@example.org."}'