Understudy is a drop-in, CPU-only HTTP proxy for System One decision models (such as TypeSafe Jev, Fireworks Rune, and Cloudflare Clef) and the OpenAI Decisions API. When pipelines, ETL jobs, event reactors, and agent loops ask the same narrow questions millions of times, Understudy forwards requests to the lead model, trains small per-question CPU models (understudents) on the lead's answers, and answers locally once an understudent reaches statistical agreement with the lead. Low-volume workloads do not need it.
At volume, local answers lower cost, reduce latency, and keep serving through lead outages. At the measured Jev and Rune rate ($0.042 per million uncached input tokens for a 3,000-byte state), 80% coverage (about 72% net of audits) saves about $45 per million calls and $45,000 per billion calls against about $2 of CPU time per billion calls for a lightweight design (about $830 for an encoder design). At larger-model rates ($0.20 to $3.00 per million input tokens), savings are 5 to 70 times higher (Cost at scale). Lightweight designs answer in 0.07 to 0.24 ms at p50 compared with 78 to 82 ms for Jev, and graduated questions keep answering from disk snapshots when the lead is slow, rate-limited, or unreachable.
Understudy accepts System One requests on POST /v1/systemone (noul, choice, and score questions) and OpenAI Decisions requests on POST /v1/decisions (predicate, choice, and score questions). Each distinct question is identified by its specification (type, instructions, and criteria), not by its field name.
flowchart LR
C["Caller"] --> U["understudy serve"]
U --> G{"Graduated, confident, not novel?"}
G -->|"yes"| S["Understudent answers locally"]
G -->|"no"| L["Lead answers unchanged"]
S --> R["Response"]
L --> R
S -.->|"sampled audit"| L
L -.->|"learning queue"| T["Refit, 5-fold CV, Wilson gate"]
T -.->|"graduate or demote"| U
For each question, Understudy retains up to 2,000 recent lead answers and refits every 100 new examples using 5-fold out-of-fold cross-validation. Eleven understudent designs cover hashed n-grams, structural features, retrieval, regex rules, and EmbeddingGemma 2 vectors (docs/understudents); in the default auto mode, candidate designs race per question and one passing candidate serves.
A question graduates when its out-of-fold agreement with the lead clears a 95% Wilson lower bound (default target 0.90 across at least 30 rows, plus a 0.80 minority-class bound across at least 15 rows). Graduated questions answer confident, in-distribution requests locally (x-understudy: local, all-zero usage), and forward novel or low-confidence states to the lead (x-understudy: lead, exact upstream bytes, status, and Retry-After). A request is answered locally only when every question in it qualifies. About 1 in 10 local answers (--audit-rate) is audited in the background against the lead, and a failing audit window demotes the question back to the lead. Crash-safe snapshots persist learned state across restarts, and SIGTERM or SIGINT drains in-flight audits and learning before saving.
Prebuilt binaries ship for Linux and macOS (x86_64 and aarch64). docs/install.md covers arm64 packages, SHA-256 checksum verification, container configuration, and pre-release tags.
| channel | command |
|---|---|
| Homebrew | brew install endgame-labs/oss/understudy |
| Shell installer | curl -fsSL https://github.com/endgame-labs/understudy/releases/latest/download/understudy-installer.sh | sh |
Debian and Ubuntu (amd64) |
curl -fsSLO https://github.com/endgame-labs/understudy/releases/download/v0.5.0/understudy_0.5.0_amd64.deb && sudo apt install ./understudy_0.5.0_amd64.deb |
| Container image | docker run -p 127.0.0.1:8787:8787 -e UNDERSTUDY_KEY -v understudy-data:/data ghcr.io/endgame-labs/understudy:latest --require-key-env UNDERSTUDY_KEY --lead-url <URL> |
| Source (Rust 1.89+) | cargo install --git https://github.com/endgame-labs/understudy |
understudy demo run exercises the full proxy lifecycle with no lead account, no credentials, no model download, and no disk writes:
understudy demo runIn one process, it starts a built-in demo lead (replaying 600 recorded Rune answers for the synthetic output_kind dataset), an in-memory understudy serve with the keywords understudent, and a caller sending the 600 requests in order. In about two seconds on a laptop, the question graduates after 100 examples (first local answer at request 102) and answers 325 of 600 requests locally (54.2%), at 97.2% agreement with the lead and 96.2% accuracy against the ground truth (the lead alone: 95.8%). The demo waits for each answer to be learned before sending the next request and seeds its audit draws, so these numbers are the same on every run.
Pass --keep-running to leave the proxy listening for manual curl calls, or run understudy demo lead and understudy demo send around a separate understudy serve process. With the container image, run docker run --rm ghcr.io/endgame-labs/understudy:latest demo run. See docs/getting-started.md for the full walkthrough.
Start in --mode shadow to forward every request to the lead, train in the background, and log candidate local answers without returning them to callers:
understudy serve --mode shadow \
--lead-url https://api.typesafe.ai/v1/systemone \
--route-key-env lead=TYPESAFE_API_KEYDrop --mode shadow to run in the default serve mode, which answers graduated questions locally with no restart. Add --no-capture --no-snapshots --no-model-download for an in-memory trial that writes nothing to disk: the first two turn off the capture log and snapshots, and --no-model-download skips the background 1.5 GB EmbeddingGemma 2 download (into the Hugging Face cache) and races only model-free designs.
Supported leads (docs/leads):
- System One (
POST /v1/systemone): TypeSafe Jev (export TYPESAFE_BASE_URL=http://127.0.0.1:8787), Fireworks Rune, Cloudflare Clef (--clef-route), and OpenAI-compatible chat endpoints (--chat-route). - OpenAI Decisions API (
POST /v1/decisions): docs/leads/openai-decisions.md. Pass--decisions-route MODEL=URL, configure akind = "decisions"lead, or pass a--lead-urlending in/decisions, and point a dedicated decisions client athttp://127.0.0.1:8787/v1. Never set a globalOPENAI_BASE_URL, because non-decision paths return 404 and are not forwarded.
| flag | behavior |
|---|---|
--mode serve (default) |
Forwards requests until a question graduates, then answers confident, in-distribution requests locally and demotes on bad audits. |
--mode shadow |
Forwards every request, trains in the background, and logs candidate local answers without serving them. |
--mode race |
Calls the lead and the local model concurrently and returns whichever valid answer finishes first. |
--mode forward |
Forwards every request and writes the capture log without training. |
--require-key-env VAR |
Requires X-Understudy-Key or Authorization: Bearer matching $VAR on every path except GET /healthz. |
--tenant-header NAME |
Isolates namespaces, learners, and snapshots per header value on a shared route. |
--graduation paced |
Controls false graduations across repeated refits and competing candidates, spending over the evidence a question has seen (opt-in; default is pointwise; sequential is the stricter older variant). |
GET /healthz and GET /status report server health and each question's state (learning, graduated, demoted, or lead_only), and GET /metrics exports the counters, per-question coverage, audits, demotions, and latency histograms for Prometheus. Before enabling local answers on production traffic, follow the production pilot (shadow mode on time-ordered traffic, independent labels, per-class error rates, p99 latency, and rollback thresholds) and review docs/security.md.
- Narrow, repetitive text questions only. Understudy targets fixed questions such as "Is this support ticket urgent?", "Does this passage mention a refund?", and "Is this tool output an error?". Broad single-question decisions over large state spaces, lookups, graded sentiment, needles in long text, heavily skewed classes, and comparisons of two changing texts (such as search reranking) stay lead-only or reach low coverage, adding 0.27 to 0.48 ms p50 forwarding overhead in shadow mode. Image inputs and Box questions are forwarded opaque and never learned.
- Agreement with the lead is not ground-truth accuracy. Graduation, audits, and demotion measure agreement with the lead, not accuracy against independent labels. On synthetic benchmarks where the lead is 99.7% to 100% accurate,
autoat the default 0.90 target loses 2.7 to 5.2 percentage points of accuracy (16 to 31 more wrong answers out of 600 than the lead alone) on three of seven graduating questions, where the benchmark marksautoharmful. Without labels,autohas no ground truth and does not avoid harmful designs.--eval-labelsgives it a labeled evaluation set and vetoes designs less accurate than the lead on it: with labels for the first 100 items, the loss on those three questions fell from 154 to 27 items over six replays, at lower coverage on payment_flip, while labels for a random 15% of the items changed nothing (A labeled evaluation set). Evaluate on labeled data, pin a design or raise--target, and run a production pilot where accuracy matters (Agreement and accuracy). - Audits demote only after wrong answers reach callers. At the default 1-in-10 audit rate with demotion judged from 20 audits over a 100-audit window, a bad learner answers about 200 times before demotion is possible, producing about 68 to 100 expected wrong local answers at 50% to 75% agreement, 150 at 85%, and 303 at 88%. The default
pointwisepolicy does not control false graduations across repeated refits, competing candidates, or threshold scans;--graduation paced(orsequential) controls repeated refits and candidates, and--abstain calibratedremoves the threshold scan (Guarantees). - Data written to disk and sent on audits.
understudy servewritesunderstudy-capture.jsonlandunderstudy-snapshots/in the working directory by default (0600files and0700directories; pass--no-capture --no-snapshotsto disable), and the defaultautounderstudent downloads the 1.5 GB embedding model into the Hugging Face cache when it is missing (--no-model-downloadto disable). Snapshots store state hashes, lead answers, and model features (embedding vectors allow approximate text recovery, andrulesstores verbatim state text). Sampled audits send locally answered states to the lead in the background, and routes without a configured lead key forward the caller'sAuthorizationheader on both forwarded requests and audits (Security). - Listener authentication and multi-tenancy.
servebinds127.0.0.1:8787with no TLS and no listener authentication unless--require-key-envis set (the container image binds0.0.0.0:8787only when--require-key-envis given). On routes without their own lead key, local answers require the lead to have accepted the sameAuthorizationheader for the same model and tenant within--caller-check-secs(default 600), so those routes cannot serve locally during a lead outage immediately after a restart. Without--tenant-header, all callers of a route and model share one set of learners and snapshots; the header is taken as sent, so tenant isolation needs a gateway that sets it and--require-tenant(security). - Encoder CPU latency and platform support. Lightweight designs (
keywords,shape,checklist, andlite) answer in 0.07 to 0.24 ms at p50, whereas encoder designs (probe,deep, andnet) run EmbeddingGemma 2 on CPU and take tens of milliseconds (deep: 66 to 89 ms at p50, comparable to a lead call); use--mode raceor--prefer-fastwhen encoder latency matters. Understudy supports Unix platforms (x86_64andaarch64Linux and macOS) only.
| page | contents |
|---|---|
| docs/getting-started.md | install, understudy demo run, three-process demo, and reading response headers |
| docs/how-it-works.md | request flow, modes, question lifecycle, novelty forwarding, learning queue, and namespaces |
| docs/graduation.md | out-of-fold CV, Wilson bounds, sequential graduation, audits, demotion, and guarantees |
| docs/understudents/README.md | comparison and selection guide for all 11 understudent designs, ladder, and auto |
| docs/leads/README.md | lead setup for TypeSafe Jev, Fireworks Rune, Cloudflare Clef, and the OpenAI Decisions API |
| docs/install.md | install channels, SHA-256 checksums, container configuration, and verification |
| docs/api.md | wire contract, error passthrough, modes, flags, status endpoints, capture log, and limits |
| docs/security.md | data visibility, files on disk, listener authentication, caller checks, and key handling |
| docs/production-pilot.md | shadow mode, independent evaluation sets, per-class errors, p99 latency, canary, and rollback |
| docs/benchmarks.md | replay methodology, cost at scale, accuracy versus agreement, per-question results, and limitations |
| docs/examples.md | graduating a gate, lead-only fallback, offline replay benchmarking, and training ladders |
| docs/diagrams.md | additional lifecycle, cost, coverage, and design-race diagrams |
| SPEC.md | precise reference for wire types, statistical formulas, CLI flags, and snapshot format |
| bench/ | understudy-bench, the Go harness for dataset synthesis, replay, and reporting |
Understudy is pre-1.0 and follows Semantic Versioning. The current release is v0.5.0. Before 1.0, patch releases (0.x.Y) contain fixes only, and minor releases (0.X.0) add features or change behavior. Release notes are in CHANGELOG.md, and the release process is in RELEASING.md.
Building from source requires Rust 1.89 or newer, and the benchmark harness in bench/ requires Go 1.24 or newer:
cargo test --release
(cd bench && go vet ./... && go test ./...)See CONTRIBUTING.md for pull request conventions and test targets, AGENTS.md for documentation and repository conventions, and SECURITY.md for reporting vulnerabilities privately.
Understudy is released under the MIT license (LICENSE). The vendored encoder in vendor/eg2cpu is licensed under MIT OR Apache-2.0 (LICENSE-MIT, LICENSE-APACHE, and PATCHED.md).