Get started
01 / 01DocumentationCorpus · reference · markdown

Single-binary Rust gateway (vitna-runtime-rs)

Source

vitna-runtime-rs is the Apache-2.0 single-binary Rust data plane for vitna-runtime and vitna-route (source in runtime-rs/). It executes the same signed policies, deterministic scoring, prompt-cache stickiness, security boundaries, and text-free ledger contract as the Node.js runtime while scaling across cores with bounded-window feature inspection on large prompts.

When to run the Rust data plane

  • You want a single static binary with no Node.js runtime dependency in a container, sidecar, or edge VM.
  • Your traffic carries large prompts (50 KB to 200 KB+ coding contexts, tool histories, or logs) at concurrent request rates where Node's single-threaded event loop adds noticeable proxy latency.
  • You want wire-compatible offline verification for both vitna-routing-policy-v1 (lane-based policies) and vitna-auto-route-policy-v1 (vitna-route policies) from one binary.

Building from source

bash
cargo build --manifest-path runtime-rs/Cargo.toml --release

The release binary lands at runtime-rs/target/release/vitna-runtime-rs (vitna-runtime-rs.exe on Windows, ~8.26 MiB stripped).

Offline policy verification

vitna-runtime-rs verify checks the canonical body SHA-256 digest, checks that the document's embedded publicKey appears in VITNA_PUBLIC_KEY (comma-separated base64 SPKI DER keys for zero-downtime key rotation), and verifies the Ed25519 signature over the exact statement bytes produced by platform/engine/policy.mjs.

bash
# Auto-route policy (vitna-auto-route-policy-v1)
VITNA_PUBLIC_KEY="$(cat route-key.pub)" \
  vitna-runtime-rs verify --policy auto-route-policy.json \
    --org acme --decision 42 --require-mode route --json

# Lane policy (vitna-routing-policy-v1)
VITNA_PUBLIC_KEY="$(cat policy-key.pub)" \
  vitna-runtime-rs verify --policy lane-policy.json --org acme --json

Exit codes match vitna-route: 0 on verified pass, 2 on CLI or missing configuration errors, and 3 on cryptographic, digest, tamper, or constraint failures.

Serving traffic

bash
# Auto-route mode under a verified signed policy
VITNA_ROUTE_POLICY=./auto-route-policy.json \
VITNA_PUBLIC_KEY="$(cat route-key.pub)" \
VITNA_LEDGER=/var/lib/vitna/ledger.jsonl \
OPENROUTER_API_KEY=... \
OPENAI_API_KEY=... \
ANTHROPIC_API_KEY=... \
  vitna-runtime-rs serve

# Instant rollback to shadow mode without modifying or re-signing the policy
VITNA_ROUTE_POLICY=./auto-route-policy.json \
VITNA_PUBLIC_KEY="$(cat route-key.pub)" \
  vitna-runtime-rs serve --shadow

# Lane-policy mode (vitna/<alias>)
VITNA_POLICY=./lane-policy.json \
VITNA_PUBLIC_KEY="$(cat policy-key.pub)" \
VITNA_LEDGER=/var/lib/vitna/ledger.jsonl \
  vitna-runtime-rs serve

Supported HTTP endpoints:

  • GET /healthz: unauthenticated liveness check ({ "ok": true, "version": "..." }).
  • GET /health and GET /status: minimal liveness body when locked and unauthenticated; full policy, mode, allowlist, conversation, and ledger status when authenticated or on unlocked loopback.
  • GET /v1/models: lists auto, vitna/auto, and provider-allowed configured models (or vitna/<alias> lanes in lane-policy mode).
  • POST /v1/chat/completions: OpenAI dialect, SSE streaming and non-streaming, auto-routing, multi-turn cache stickiness, failover, and named-model passthrough.
  • POST /v1/messages: Anthropic Messages API dialect, SSE streaming and non-streaming passthrough with ledger attribution.
  • POST /v1/route/explain: pure decision introspection with no upstream calls and no ledger writes.

Explaining decisions locally

bash
vitna-runtime-rs explain --policy auto-route-policy.json \
  --public-key "$(cat route-key.pub)" --json request.json

Security and ledger invariants

vitna-runtime-rs enforces the same invariants as vitna-runtime and vitna-route:

  • Refuses to boot unsigned mode: "route" configurations fail-closed.
  • Refuses to bind any non-loopback address (0.0.0.0, LAN IPs, hostnames) unless VITNA_INBOUND_KEY or VITNA_ROUTE_API_KEYS is configured.
  • Performs constant-time authentication over SHA-256 digests for Authorization: Bearer <key> and x-api-key.
  • Rejects browser-forged non-loopback Host headers, Origin headers on POST /v1/*, and non-application/json POST /v1/* requests with 403 whenever no inbound key is set.
  • Enforces VITNA_ALLOW_PROVIDERS across auto-routing, shadow serving, passthrough routes, /v1/messages, /v1/models, and lane resolution.
  • Appends text-free JSONL rows to VITNA_LEDGER containing numeric feature counts, decision reasons, policy digest, latency, and provider-reported token counts, compatible with vitna-runtime-profile (unitProfiles). Prompt and completion text are never written to disk.
  • Makes zero network calls to vitna.ai.

Measured loopback performance

Head-to-head comparison via node runtime-rs/bench/compare.mjs against a local loopback mock upstream (both gateways serving the same signed route policy and appending one JSONL ledger row per request on an open file descriptor; Windows x86_64, rustc 1.98.1, Node v24.19.0):

Scenariovitna-runtime-rs (--release)Node vitna-routeThroughput speedup
1 KB (c=16)1,761.6 req/s (p50 8.14 ms, p99 25.51 ms)720.5 req/s (p50 19.44 ms, p99 51.49 ms)2.45x
200 KB (c=1)245.1 req/s (p50 4.01 ms, p99 4.80 ms)58.5 req/s (p50 15.67 ms, p99 30.29 ms)4.19x
200 KB (c=4)939.8 req/s (p50 3.82 ms, p99 10.44 ms)70.5 req/s (p50 54.13 ms, p99 89.43 ms)13.33x

See runtime-rs/README.md for full details and reproduction commands.