Model routing
A team that pays per token spends frontier prices on work that a cheap model does as well, such as a typo fix or a version bump. The model router picks a cheap or a frontier model for each task that zt start launches. zt then passes that model to the agent when it starts.
The router is off until a lead of the project turns it on. It routes only sessions that you start with --credential api-key. A session on a subscription keeps the agent’s own model.
Zentri never sees the agent’s model traffic. It never collects, stores, proxies, or resells model access or a model credential. The agent talks to its provider with your own credentials. The router changes one thing, the model setting on the agent’s command line or config.
How it works
Section titled “How it works”Where the decision happens
Section titled “Where the decision happens”zt startregisters the intent with aroutethat names the agent kind and the credential kind,api_keyorsubscription.- The coordinator classifies the prompt by the rules, and by the LLM tiebreak when the project asks for it.
- The coordinator records the route in
session_routes, in the same transaction that creates the session, and returns the tier, the model, the rule, and the classifier. zt startchecks the model name again and passes it to the agent.
zt start asks for a route only for the agent commands claude, codex, and opencode. It asks for none when the agent command already has --model, -m, or --model=, so a model you name yourself wins.
The rules
Section titled “The rules”The rules run in the coordinator and send nothing anywhere. The first rule that matches decides the tier.
| Order | Rule | Matches when the prompt | Tier |
|---|---|---|---|
| 1 | frontier_term |
Has a frontier term | frontier |
| 2 | long_prompt |
Has more than 60 words, or names more than 3 distinct file paths | frontier |
| 3 | cheap_term |
Has a cheap term | cheap |
| 4 | short_prompt |
Has 12 words or fewer | cheap |
| 5 | default |
Matched no rule above | frontier |
When no rule is sure, the router picks frontier. A wrong cheap pick costs more than it saves, because a cheap model that fails a hard task wastes the session.
Every project starts with these terms:
- Frontier terms:
architecture,architectural,concurrency,concurrent,migration,migrations,security,race,races,refactor,refactoring,performance,design, andredesign. - Cheap terms:
typo,typos,rename,renames,bump,bumps,docs,comment,comments,lint,format,formatting, andchangelog.
A term matches a whole word, in any case. A project’s own terms add to these defaults. Each list takes at most 64 terms, and each term is one word of letters and digits of at most 40 bytes. The coordinator lowercases, sorts, and deduplicates them.
The LLM tiebreak
Section titled “The LLM tiebreak”With "llm": true, a prompt that falls to rule 5 asks the coordinator’s LLM for cheap or frontier. The tiebreak runs only when all of these are true:
- The project’s config sets
"llm": true. - The coordinator has an LLM, set by
ZENTRI_LLM_BASE_URL. - The prompt fell to rule 5,
default. - The route will apply a model, because the session is
api_keyand the config names models for the agent.
The call has a 3-second timeout and a strict answer schema. A clean cheap or frontier answer in time sets the tier, and the route’s classifier is llm. A timeout, an error, or any other answer keeps frontier, and the classifier stays rules. The LLM is the endpoint that the coordinator’s operator configured, never a user’s credential. The tiebreak uses it whatever ZENTRI_LLM_STEPS says.
Credential kinds
Section titled “Credential kinds”zt start --credential declares what the agent authenticates with. The default is $ZENTRI_CREDENTIAL, then subscription. zt reads no credential to find out.
--credential |
Route auth |
Result |
|---|---|---|
api-key |
api_key |
The agent gets the routed model. |
subscription (default) |
subscription |
The agent keeps its own model. The route still records the tier and the rule. |
A subscription has its own model picker and limits, so the router leaves its model alone. A false api-key declaration changes only the model setting of your own agent, which still runs on your own credentials. The provider may refuse that model.
How the agent gets its model
Section titled “How the agent gets its model”| Agent | How zt passes the model |
|---|---|
Claude Code (claude) |
--model MODEL, before the prompt |
Codex (codex) |
--model MODEL, before the prompt |
OpenCode (opencode) |
The model key in the OPENCODE_CONFIG_CONTENT document, because its root command takes no model flag. OpenCode names models provider/model. |
In an openshell sandbox, Claude Code and Codex get the same flag. For OpenCode the launcher passes {"model": MODEL} as OPENCODE_CONFIG_CONTENT, and the managed kit under /etc/opencode supplies the rest.
A model name must match ^[A-Za-z0-9][A-Za-z0-9._:/@-]{0,127}$. The coordinator checks the name when a lead sets it, and zt checks it again before it passes it. A name cannot start with a dash, so it cannot read as a flag. When the check in zt fails, the agent starts on its own model, and zt prints this warning:
zentri: the coordinator routed to "NAME", which is not a model name; the agent keeps its own model.When the router applies no model
Section titled “When the router applies no model”A route that applies no model says why in its skipped field. zt start prints the reason on its model line.
skipped |
zt start says |
Recorded |
|---|---|---|
disabled |
the project's router is off |
No |
subscription |
the agent runs on a subscription; --credential api-key routes an API key session |
Yes |
no_model |
the router has no models for this agent |
Yes |
no_prompt |
the coordinator holds no prompt to classify |
Yes |
A route row holds the agent kind, the credential kind, the tier, the model, the rule, the classifier, and the time. It never holds the prompt. The coordinator writes a router.update entry to the audit log when a lead changes the config, with the switches, the agents, and the terms, and never the models.
Use it
Section titled “Use it”A lead writes the config as JSON. A field left out is off or empty, and an unknown field is refused. This example is the one in zt router set --help:
{ "enabled": true, "models": { "claude": { "cheap": "claude-haiku-4-5", "frontier": "claude-opus-4-1" }, "codex": { "cheap": "gpt-5.1-codex-mini", "frontier": "gpt-5.1-codex" }, "opencode": { "cheap": "anthropic/claude-haiku-4-5", "frontier": "anthropic/claude-opus-4-1" } }, "frontier_terms": ["billing"], "cheap_terms": ["copy"], "llm": false}An agent missing from models keeps its own model. The file may be at most 64 KiB.
zt router set --file router.jsonzt router showzt router set --file - reads stdin. Only a lead may set the router. For anyone else, zt prints only a lead of <project> may set its router. Anyone with a role in the project may run zt router show, and --json prints the API’s view. Both commands take --project.
zt router show prints the state, the models for each agent, the tiebreak, and the terms:
Model router of <project>: on, for sessions started with --credential api-key claude cheap claude-haiku-4-5, frontier claude-opus-4-1 LLM tiebreak off frontier terms architecture, architectural, ...; the project adds billing cheap terms typo, typos, ...; the project adds copyLast set <time>.Start a routed session with --credential api-key, or set ZENTRI_CREDENTIAL=api-key:
zt start --credential api-key "Fix the typo in README.md"zt start adds a model line to its output. A routed session shows the model, the tier, and the rule, and adds LLM tiebreak when the LLM decided. A session the router skipped shows agent default (not routed: <reason>).
model claude-haiku-4-5 (cheap tier, rule cheap_term)zt stats counts the routes that the router decided while it was on. zt stats --json gives routing as counts of cheap, frontier, and skipped. The text output says N cheap, N frontier, N on the agent's own model.
The API endpoints are GET and PUT /v1/projects/{project_id}/router, through the actions router.read (viewer) and router.update (lead). The CLI reference lists every flag, and Configuring model routing walks through a setup.
What has run
Section titled “What has run”scripts/e2e-m5b.sh runs the router against the coordinator, with a fake claude that records its arguments. An engineer’s zt router set is refused, and a lead’s is accepted. With the router on, an api-key typo fix launches claude with --model claude-haiku-4-5 by cheap_term. A redesign launches it with --model claude-opus-4-1 by frontier_term. A subscription task gets no --model. session_routes then holds three rows, and zt stats --json gives routing as 1 cheap, 1 frontier, and 1 skipped. ADR-0011 records five passing runs in a row on macOS with Docker Desktop, on 2026-11-29.
Limitations
Section titled “Limitations”- The rules match keywords. A hard task written in plain words can match a cheap term or the short-prompt rule.
- The default terms are English words. A prompt in another language falls to the word counts and rule 5, unless the project adds its own terms.
- A session created through
POST /v1/projects/{project_id}/sessions, without an intent, is not routed. - The coordinator decides the route before it knows the registration’s class. With
"llm": true, a prompt can reach the LLM for a registration that ends as a duplicate. - A lead’s change made between the decision and the transaction applies from the next start.
- An agent-level
modelin OpenCode’s config, or amodelin managed config under/etc/opencode, outranks the routed one. - The coordinator checks only the characters of a model name, so a lead can set a name that the agent refuses.
Related pages
Section titled “Related pages”- Configuring model routing walks through turning the router on for a project.
- Seats and API keys explains why only API key sessions are routed.
- Never share a subscription covers how Zentri treats consumer subscriptions.
- The sandboxing model explains how a sandboxed agent gets its model.
- The CLI reference lists the flags of
zt router,zt start, andzt stats. - The environment reference lists
ZENTRI_CREDENTIALand theZENTRI_LLM_*variables.