Deploy the gateway

Early access: for pilots and design-partner deployments

This page describes gateway v2: stateless processes in front of one PostgreSQL, bounded guard queues with load shedding, a hash-chained ledger per tenant. It has been tested heavily on one machine and on one A100, and it has not had an independent security review, a high-availability drill, or a high-availability database of its own. See "Limits that remain" before you rely on it for production traffic. The earlier single-node build (one process, SQLite) is the reference build the published measurements came from; it is not what this page documents.

Components

  • Gateway: a Node.js service, run as one or more identical processes. It validates, authenticates, rate-limits, reserves credit, runs the guard pipeline, forwards to your model, checks the completion, settles and appends to the ledger.
  • PostgreSQL 16 or later: accounts, keys, credit reservations, the per-tenant ledger, anchors, the upstream registry and shared rate counters. Every gateway process needs it.
  • The safety gate: the checks that judge every prompt and every answer. The release bundle brings it up with one file, deploy/safety-gate-up.sh; its settings are in the bundled gateway.env.example.
  • Your upstream models: any OpenAI-compatible endpoint, registered by an administrator. Upstream API keys are never stored in the database; a registry row names the environment variable (or <NAME>_FILE) that holds the key.
  • A reverse proxy or load balancer that checks /ready and, unless you terminate TLS in the gateway, ends TLS.

Quick start

npm install
export DATABASE_URL=postgres://user:pass@localhost:5432/valetta
export ADMIN_TOKEN=$(openssl rand -hex 24)
# the safety gate's addresses are written by deploy/safety-gate-up.sh (see the bundled gateway.env.example)

npm run admin -- migrate
npm run admin -- create-account --name "Acme" --email [email protected] --credits-usd 25
npm run admin -- create-key --account acc_xxxx          # prints the key once; only its hash is stored
npm run admin -- add-upstream --model acme/model --url http://my-model-server:8000/v1 --upstream-model my-model --key-env MODEL_KEY
npm start

Accounts, keys, upstreams, top-ups, anchors and recovery are administrator commands only. The gateway has no registration or management API, so there is nothing for an attacker to call.

curl -s http://127.0.0.1:8787/v1/chat/completions \
  -H "Authorization: Bearer vk_live_..." -H "content-type: application/json" \
  -d '{"model":"acme/model","messages":[{"role":"user","content":"Hello"}]}'

Response headers carry the decision: x-valetta-verdict, x-valetta-risk-category and the policy identity. The older x-wattsfor-* names are sent as well while LEGACY_HEADERS=true (the default), so existing clients keep working; the API reference uses those names.

Sizing

  • The gateway is not the limit. With near-instant guards, one process on a laptop served more than a thousand requests per second with correct decisions and exact books. The guard tier is the limit.
  • Measured so far, the whole gate (output guard on) sustained 4.6 to 9.3 requests per second on one NVIDIA A100-SXM4-40GB shared by all of its services (2026-11-22). These figures are for one GPU class, one host and a stub model upstream; no other GPU, no multi-host and no multi-GPU test has been run, and your model needs capacity on top.
  • Decisions can differ between serving stacks and builds. Re-measure on your own labelled sample before any change goes live.
  • Use the guard-queue settings to size one process: set each backend's concurrency to about 1.5 × (the server's parallel capacity ÷ number of gateway processes), and MAX_INFLIGHT_REQUESTS to about (sustainable requests per second) × (acceptable seconds per request). Past that, requests are refused in milliseconds with a 503 and Retry-After, and are not billed.
  • The safety gate's internal services have no authentication. Bind them to localhost or a private network and firewall everything else; container-published ports can bypass host firewalls.

Configuration

Everything is an environment variable, validated at start-up: a mistyped value stops the process instead of silently weakening a limit. The bundle ships a commented example that a test parses, so it cannot drift from the code.

VariableDefaultPurpose
DATABASE_URL, PG_POOL_MAXrequired, 20PostgreSQL. Pool size × number of processes must stay under the database's connection limit. For TLS to the database add ?sslmode=verify-full&sslrootcert=/path/ca.pem to the URL.
ADMIN_TOKENunsetEnables /metrics and the all-tenant audit verification. Unset disables both.
<NAME>_FILEunsetFor DATABASE_URL, ADMIN_TOKEN and any upstream key variable: read the secret from a file (systemd credentials, container secrets) so it never sits in the process environment. Setting both the variable and its file is refused.
TLS_CERT_FILE, TLS_KEY_FILEunsetServe https directly (TLS 1.2 or later). Both or neither. Replace the files and send SIGHUP to load a renewed certificate without a restart. Most deployments end TLS at the proxy instead.
PORT, HOST, INSTANCE_ID8787, 127.0.0.1, randomListener. Use 0.0.0.0 only when a load balancer in a private network is the sole client.
RATE_LIMIT_BACKENDmemorymemory is exact per process. With more than one process use postgres, which is shared and guarantees the limit across any 60-second window; after a burst, recovery can lag the exact window by up to 5 seconds.
MAX_KEY_RPM, MAX_KEY_TPM600, 1000000Ceilings on any key's limits.
MAX_INFLIGHT_REQUESTS0 (off)Cap on chat requests being processed at once.
INPUT_GUARD_KINDpolicySelects how the safety gate judges. The exact values are in the deployment bundle.
*_URL (the safety gate's backends)local defaultsWhere each backend is served; the bring-up file writes them. Use https URLs, and NODE_EXTRA_CA_CERTS for a private CA, to encrypt these links.
ENABLE_OUTPUT_GUARDtrueInspect completions. Streams are buffered while it is on.
GUARD_WINDOW_CHARS, GUARD_WINDOW_OVERLAP, GUARD_MAX_CHARS3500, 500, 100000Window size for long inputs; above the maximum, input is refused with 413.
*_CONCURRENCY, *_MAX_QUEUE, GUARD_QUEUE_TIMEOUT_MS8, 64, 2000Bounds on calls into each guard backend per process. New work is shed first; work already started is protected.
GUARD_CACHE_ENTRIES10000Verdict cache keyed by a hash of the text; it holds no text, lives in memory and is per process. Helps traffic with a long repeated system prompt.
UPSTREAM_TIMEOUT_MS, RESERVATION_TTL_SECONDS120000, 900The reservation timeout must exceed the longest possible request; the process refuses to start otherwise.
ANCHOR_INTERVAL_MS0 (off)Periodic ledger snapshots. They only mean something once copied off the database (see below).
LICENCE_MODE, LICENCE_FILE, LICENCE_GRACE_DAYS, LICENCE_EXPIRED_ACTIONoff, /etc/valetta/licence.json, 30, refuse-startLicence checking, offline. See "Licence checking" below.
DRAIN_SECONDS30On SIGTERM the gateway stops being ready at once and lets in-flight requests finish for up to this long.

Health and metrics

  • GET /health: the process is alive. It reports the guard kind, the policy identity and hash, and the guard limits, and does not touch the database. Alert on a policy hash that is not the one you approved.
  • GET /ready: the database is reachable and the process is not draining. Point the load balancer here.
  • GET /metrics: Prometheus text, with the admin token.
  • GET /v1/audit/verify: a tenant verifies its own ledger chain with its API key. GET /api/audit/verify (admin token) verifies every chain and the anchors.

Licence checking

The sidecar is licensed per cluster. A licence is a small signed file issued for your cluster's id (npm run admin -- cluster-id prints it). The gateway verifies the signature, the validity dates and the cluster id offline, so it works in air-gapped and sovereign environments and nothing is sent to us. LICENCE_MODE=warn reports the state on /health and /metrics without ever blocking; enforce refuses to start without a valid licence. After expiry there is a grace period (30 days by default); then, as agreed with you, either a restart is refused (the default; running processes keep serving) or the gate answers 503 licence_expired. A renewed file takes effect within six hours without a restart. A licence is not copy protection: it cannot stop a database being copied to a second cluster, which the agreement and the per-tenant ledger cover.

Operations checklist

  • TLS at the proxy, or in the gateway with the TLS files. Encrypt the links to PostgreSQL, the guards and the upstreams as well: they are plain HTTP unless you configure https.
  • Backups: the bundle includes a daily backup script (logical dump, optional encryption, off-box copy, 35-day retention), a restore test that restores into a scratch database and verifies every ledger chain, and timers for both. Run the restore test weekly: a backup that has never been restored is a hope. A dump gives a recovery point of the dump interval; use point-in-time recovery for less.
  • Anchors: tamper evidence is exactly as strong as where the anchors are kept. Run the anchor export (hourly) and send the copies to write-once storage that a database administrator cannot reach.
  • High availability of the database is the database service's job: managed PostgreSQL, Patroni or similar. Run at least two gateway processes behind the load balancer and set RATE_LIMIT_BACKEND=postgres. Rehearse a failover and record the numbers.
  • Rotate ADMIN_TOKEN, the demo or customer keys you issued, and upstream provider keys on a schedule.
  • Re-run the benchmark and your own labelled sample after every model, serving-stack or policy change.
  • Run the regression suite (the bundle's tests start their own throwaway PostgreSQL) before each upgrade.
  • Releases and upgrades: a release is a tarball with a per-file manifest and a software bill of materials, with a signed checksum file. Verify the signature and checksums (the bundle includes the verifier) before installing. Migrations only add, so a code rollback is safe. Upgrade one instance at a time, waiting for /ready, after a backup and a passing restore test.

Limits that remain

  • No independent security review or penetration test yet (the security page says the same).
  • One PostgreSQL service is a single point of failure unless you run it highly available. Very hot single tenants are bounded by their account row lock.
  • Upstream keys come from environment variables or files, not a secrets manager. Anchors are not shipped off-box unless you run the export.
  • No payment rails: credit top-ups are administrator commands.
  • The verdict cache is per process and bounded by entry count, not bytes.
  • Decisions depend on the serving stack and weight build; the published evidence is not re-validated for a stack you choose.
  • Container images and systemd units in the bundle have not been built or run on a production host; the images have been run on a rented A100. The release is a verified tarball, not an installer or an image.
  • No high-availability drill has been run on multi-host infrastructure, so we give no uptime figure. Today the service is operated by one person; pilots are best effort in business hours.
  • The safety gate's internal services have no authentication: keep them on a private network.
  • Re-validation of the decisions on serving stacks and weight builds other than the ones measured is a written procedure with acceptance criteria that has not been run.