Configuring model routing
The model router picks a cheap or a frontier model for each task that zt start launches. It decides by rules on the prompt, and zt passes the model to the agent as its model flag. A typo fix can run on a cheap model while a redesign runs on a frontier one. This guide turns the router on for a project, starts routed sessions, and reads the counts.
The design is in ADR-0011 in the Zentri repository, under docs/adr/. For the idea behind it, see model routing.
Every user brings their own agent credentials. Zentri never collects, proxies, stores, or resells model access or consumer subscription tokens. The router only names a model. The agent talks to its provider with the user’s own credentials, and Zentri never sees that traffic.
Before you start
Section titled “Before you start”- The lead role in the project. Only a lead can change the router. Anyone who can view the project can read it. See roles and skill levels.
- Agents launched as
claude,codex, oropencode. No other agent is routed. - Engineers who run their agents on API keys. The router changes nothing for a session that runs on a subscription.
- Optional: an LLM on the coordinator (
ZENTRI_LLM_BASE_URLandZENTRI_LLM_MODEL), for the tiebreak in step 2. - Optional: a data key on the coordinator (
ZENTRI_DATA_KEY_FILE), to route queued starts. See what can go wrong.
How the router decides
Section titled “How the router decides”The router reads the task’s prompt and takes the first rule that matches:
| Order | Rule name | 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 file paths | frontier |
| 3 | cheap_term |
Has a cheap term | cheap |
| 4 | short_prompt |
Has 12 words or fewer | cheap |
| 5 | default |
Matched nothing above | frontier |
The built-in terms:
| Kind | Terms |
|---|---|
| Frontier | architecture, architectural, concurrency, concurrent, migration, migrations, security, race, races, refactor, refactoring, performance, design, redesign |
| Cheap | typo, typos, rename, renames, bump, bumps, docs, comment, comments, lint, format, formatting, changelog |
A term matches a whole word, in any case. The prompt is split at every character that is not a letter or a digit, so README.md gives the words readme and md. A project’s own terms add to these. They never replace them.
Here is how some prompts route, with the project terms billing (frontier) and copy (cheap) from step 2:
| Prompt | Tier | Rule |
|---|---|---|
| Fix the typo in README.md | cheap | cheap_term |
| Redesign the session token refresh to remove the race between concurrent refreshes | frontier | frontier_term |
| add CSV export to the reports page | cheap | short_prompt |
| Update the copy on the billing page | frontier | frontier_term |
| Update the copy on the pricing page | cheap | cheap_term |
| Bump the Go toolchain and update the docs in web/a.md web/b.md web/c.md web/d.md | frontier | long_prompt |
| Add pagination to the audit log list in the admin console and keep the filters when the page changes | frontier | default |
A frontier term wins over a cheap one, and four file paths win over bump and docs. When no rule fits, the task gets the frontier model. A wrong cheap pick can waste a session, so the router leans frontier when unsure.
These results come from running the router’s Classify function on each prompt. The first two are the prompts that scripts/e2e-m5b.sh launches.
1. Read the current settings
Section titled “1. Read the current settings”zt router showA project that never set its router prints:
Model router of web: off models none; every agent keeps its own LLM tiebreak off frontier terms architecture, architectural, concurrency, concurrent, migration, migrations, security, race, races, refactor, refactoring, performance, design, redesign cheap terms typo, typos, rename, renames, bump, bumps, docs, comment, comments, lint, format, formatting, changelog--project picks the project. It defaults to $ZENTRI_PROJECT, then your zt config. --json prints the API’s settings, with the built-in terms under defaults and llm_available, which says whether the coordinator has an LLM.
2. Write the settings file
Section titled “2. Write the settings file”Save this as router.json. It is the example from 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}| Field | Meaning |
|---|---|
enabled |
Turns the router on. |
models |
A cheap and a frontier model for each of claude, codex, and opencode. An agent left out keeps its own model. |
frontier_terms, cheap_terms |
Words added to the built-in terms. At most 64 in each list, each one word of letters and digits, at most 40 bytes. They are stored lowercased, sorted, and without repeats. |
llm |
When true, a prompt that only rule 5 decides asks the coordinator’s LLM for cheap or frontier. |
The rules for the file:
- It replaces all of the project’s settings. A field you leave out is off or empty, so keep the models in the file when you only change the terms.
- An unknown field is refused, so a misspelled one never turns a setting off silently.
- A model name matches
^[A-Za-z0-9][A-Za-z0-9._:/@-]{0,127}$. The coordinator checks only the characters, not whether the model exists. - OpenCode names its models
provider/model. - The file is at most 64 KiB.
The model names above are examples. Use the models your engineers’ API keys can reach.
The LLM tiebreak
Section titled “The LLM tiebreak”With "llm": true, the router asks the coordinator’s LLM only when rule 5 decided, and only for a session that will get a model. It waits at most 3 seconds. A timeout, an error, or any answer other than cheap or frontier keeps frontier.
3. Apply the settings
Section titled “3. Apply the settings”zt router set --file router.jsonzt prints the new settings. With the file above, on a coordinator with no LLM:
Model router of web: on, for sessions started with --credential api-key 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 LLM tiebreak off frontier terms architecture, architectural, concurrency, concurrent, migration, migrations, security, race, races, refactor, refactoring, performance, design, redesign; the project adds billing cheap terms typo, typos, rename, renames, bump, bumps, docs, comment, comments, lint, format, formatting, changelog; the project adds copyLast set Nov 30 14:05.The time is in your local zone. Use --file - to read the settings from stdin.
With "llm": true and no LLM on the coordinator, the tiebreak line says:
LLM tiebreak on, but the coordinator has no LLM, so the rules decide aloneThe coordinator records each change in the audit log as router.update, with the switches, the agents, and the terms, but not the model names.
zt router set calls PUT /v1/projects/{project_id}/router, and zt router show calls GET on the same path. Both are in the HTTP API reference.
4. Start a routed session
Section titled “4. Start a routed session”An engineer declares that the agent runs on an API key:
zt start --credential api-key "Fix the typo in README.md"Or once per shell:
export ZENTRI_CREDENTIAL=api-keyThe launch output gains a model line:
Started session 3f9a12bc for intent 7d0e44a1 (new). branch zentri/fix-the-typo-in-readme-md-<id> worktree /home/ana/.local/share/zentri/worktrees/web/fix-the-typo-in-readme-md-<id> model claude-haiku-4-5 (cheap tier, rule cheap_term)Attach with: zt attach 3f9a12bcWhen the LLM decided, the line ends with LLM tiebreak:
model claude-opus-4-1 (frontier tier, rule default, LLM tiebreak)zt puts the model on the agent’s command line: --model MODEL for Claude Code and Codex. OpenCode’s main command has no model flag, so zt sets model in the OpenCode config it passes in OPENCODE_CONFIG_CONTENT.
zt reads no credential. --credential is only what you declare. The default is subscription, which keeps the agent’s own model.
When the agent keeps its own model
Section titled “When the agent keeps its own model”When a route comes back without a model, the line says why:
| Line | Cause |
|---|---|
agent default (not routed: the project's router is off) |
enabled is false. |
agent default (not routed: the agent runs on a subscription; --credential api-key routes an API key session) |
You did not declare api-key. |
agent default (not routed: the router has no models for this agent) |
models has no entry for this agent. |
agent default (not routed: the coordinator holds no prompt to classify) |
A queued start, and the coordinator kept no raw prompt. |
No model line at all means zt asked for no route. That happens for an agent other than claude, codex, or opencode, and when the agent command already names a model:
zt start --agent "claude --model claude-opus-4-1" "plan the billing migration"A model you put on the command line with --model, -m, or --model= always wins, so the agent never gets two model flags.
5. Count the routes
Section titled “5. Count the routes”zt statsAmong the other metrics:
Model routing: 1 cheap, 1 frontier, 1 on the agent's own model Sessions the model router routed while it was on. Only an API key session gets a routed model.The counts cover the last 30 days. Change the window with --days N, from 1 to 365. A route made while the router was off is not counted. A session on a subscription, or for an agent with no models, counts as on the agent’s own model. zt stats --json gives the same numbers under routing, as cheap, frontier, and skipped.
Turn it off
Section titled “Turn it off”Set "enabled": false. Keep the rest of the file if you want the same models and terms when you turn it back on:
jq '.enabled = false' router.json > router-off.jsonzt router set --file router-off.jsonSessions started from then on keep their agent’s own model. Running sessions keep the model they started with.
What can go wrong
Section titled “What can go wrong”zt prints an error after error: . The coordinator’s refusals start with coordinator answered 400 invalid_request: , followed by the reason.
| Message | Cause and fix |
|---|---|
only a lead of web may set its router: ... |
You are not a lead of the project. Ask a lead to run zt router set. |
read the router settings in router.json: json: unknown field "modles" |
A field is misspelled. Fix the name. |
... unknown agent "gemini": use claude, codex, or opencode |
models names an agent the router does not route. |
... agent claude needs a cheap and a frontier model, each matching ^[A-Za-z0-9][A-Za-z0-9._:/@-]{0,127}$ |
A model is missing, empty, or has a character outside the pattern. |
... frontier_terms: "data model" must be one word of letters and digits, at most 40 bytes |
A term has a space or punctuation. Add each word on its own. |
--credential "apikey" is not api-key or subscription |
Use api-key exactly. |
zentri: the coordinator routed to "...", which is not a model name; the agent keeps its own model. |
zt checks the name again before it puts it on the command line. The agent starts on its own model. |
| The agent fails right after it starts | The model does not exist, or your key cannot reach it. Fix the name in the settings file and set it again. |
Every queued start says the coordinator holds no prompt to classify |
zt start --queued and Slack requests route on the prompt the coordinator stored at registration. It stores raw prompts only with ZENTRI_DATA_KEY_FILE set. |
Limitations
Section titled “Limitations”- No real Claude Code, Codex, or OpenCode has started on a routed model. The tests and
scripts/e2e-m5b.shlaunch a fakeclaudeand check its command line. The Codex flag and the OpenCode config key were read in each project’s source, not run. - The rules are keyword rules. They miss a hard task described in easy words. The frontier default limits the cost of that.
- The built-in terms are English. A prompt in another language falls to the word counts and rule 5 unless the project adds its own terms.
- Only sessions that
zt startcreates through an intent are routed. A session created throughPOST /v1/projects/{project_id}/sessionsis not. - An agent-level
modelin OpenCode’s own config, or amodelin managed config under/etc/opencode, outranks the routed one. - The route is decided before the coordinator knows whether the task is a duplicate. With
llmon, a prompt can reach the LLM for a task that ends up asking you to resolve a duplicate. - A change a lead makes while a start is being decided applies from the next start.
- No
ztcommand lists the route of each past session.zt startprints it once, andzt statscounts them.