Shadow evals for auto routers
A shadow eval answers one question before you move traffic onto an auto router: would the router have answered these real requests as well as the model the team uses now, and for how much less. The gateway copies a small share of a target's live requests, sends each copy through the router as well, asks a judge model to compare the two answers without knowing which is which, and reports who won by difficulty tier, by the model the real request ran on and by target. Users only ever receive the real answer. Shadow evals are part of the free gateway and need a connected database.
A real-world scenario
The platform team pays for claude-sonnet-5-5 on every request from its support assistant. An admin has built an auto router called smart that sends easy questions to claude-haiku-5-5. Before switching the team's key to smart, the admin runs a seven day shadow eval on 10 percent of the team's traffic with a 25 dollar budget. At the end the eval shows the router matched or beat the current model on 68 percent of judged turns and lost mostly on the hardest tier, at a third of the cost. The admin raises the hard tier to a stronger model, runs the eval again, and switches the key when the numbers hold.
Step by step
In the Admin UI
- Open
/ui/cost-optimizationas a proxy admin, pick the Auto-Router tab and then the Shadow Evals sub tab. - In Start a shadow eval, leave Direction on Adoption check: key's traffic vs the router.
- Pick at least one target under Keys to shadow, Teams to shadow or Users to shadow. Team and user targets also cover traffic that arrives with a JWT instead of a virtual key.
- Optionally narrow the sample with Only on models, which keeps only the targets' requests for the chosen model groups.
- Pick the routers to test under Auto-routers, up to four. Every router sees the same sampled requests, so they compare head to head.
- Set Traffic sampled (percent, default 10), Duration (default 7 days) and Spend budget (dollars per target, default 10). Pick a Judge model, preferably one with the Recommended label.
- Click Start shadow eval. The eval card appears with the status running and refreshes every 15 seconds.
- Read the headline, the verdict bar and the slice tables as verdicts arrive. Click Stop to end the eval early. Finished evals stay under Previous evaluations.
To check a router that a team already uses, choose Regression check: router's picks vs a baseline instead, pick exactly one router and a Baseline model. The gateway then copies requests the router did serve and compares them with the baseline.
With curl
curl -X POST http://localhost:4000/auto_router/shadow_eval/start \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{
"team_ids": ["team-platform"],
"router_names": ["smart"],
"direction": "forward",
"shadow_percentage": 10,
"judge_model": "claude-sonnet-5-5",
"duration_days": 7,
"max_budget": 25
}'
| Field | Default | What it does |
|---|---|---|
api_key_ids, team_ids, user_ids | none | The targets. At least one is required and at most 100 in total. Each target gets its own budget and stop state. A key is named by its token hash, the value the key list reports. |
models | every model | Keep only the targets' requests for these model groups. Forward jobs only. |
router_names | none | The auto routers to test, at most four. router_name is accepted for a single one. More than one router needs direction: forward. |
direction | forward | forward tests adopting the router. reverse tests whether a target already on the router still gains from it and needs baseline_model. |
baseline_model | none | Reverse jobs only, and required there. A plain model, not another auto router. |
shadow_percentage | required | The share of eligible requests to copy, from 0.1 to 100. |
judge_model | anthropic/claude-sonnet-5 | The model that compares the two answers blind. It must be a plain model the gateway can call, and it must not serve either arm, because a judge rates its own answers higher. The Admin UI has no default and asks you to pick one. |
duration_days | 7 | The window, 1 to 30 days. |
max_budget | 10 | The cap in dollars per target on the shadow and judge calls, from 0.01 to 10000. A job over three targets can spend about three times this. |
Follow the job and read its results.
curl "http://localhost:4000/auto_router/shadow_eval?limit=20" -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
curl http://localhost:4000/auto_router/shadow_eval/3f1c2a9e-5b7d-4c21-9e0a-6d8f4b2c1a73 -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
curl -X POST http://localhost:4000/auto_router/shadow_eval/3f1c2a9e-5b7d-4c21-9e0a-6d8f4b2c1a73/stop -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
Expected result
The start call answers 201 with the job, its targets and ends_at seven days out.
{
"job_id": "3f1c2a9e-5b7d-4c21-9e0a-6d8f4b2c1a73",
"targets": [{"target_type": "team", "target_id": "team-platform", "target_alias": "Platform", "max_turns": 10000, "max_budget": 25.0, "stopped_at": null, "attempt_count": 0, "spend": 0.0}],
"router_names": ["smart"],
"direction": "forward",
"judge_model": "claude-sonnet-5-5",
"shadow_percentage": 10.0,
"created_at": "2026-11-14T09:00:00Z",
"ends_at": "2026-11-21T09:00:00Z"
}
Within about ten seconds every gateway replica starts sampling. GET /auto_router/shadow_eval/{job_id} adds judged_count, error_count, judge_spend, last_error and results. The results carry by_tier, by_current_model and by_router slices, each with the turn count, the win rate of the real and the shadow answer, the tie rate, the average judge confidence and the spend on both sides, plus overall_shadow_win_rate_pct, overall_tie_rate_pct and funnel counts of requests that were not sampled, could not be judged, were shed under load or were withheld. Each target also carries its own verdicts slice. The Admin UI renders the same data as the headline, the verdict bar and the slice tables.
Shadow and judge calls are billed to the identity of the sampled request, so they appear in that key's spend, but they are left out of request counts and of the auto router adoption metrics. A target stops sampling when its own budget is spent, when the window ends or when the job is stopped, and one target running out of budget never stops the others. A job stops within about ten seconds of the stop call and keeps every attempt it recorded.
What gets sampled
Only successful requests to /v1/chat/completions, /v1/messages and /v1/responses can be sampled. Failed requests, requests with message logging turned off (the gateway cannot judge what it may not read), and the gateway's own internal and eval traffic are skipped without being counted. Of the requests that are eligible, the funnel counts tell you why one was not judged.
| Count | Why it grows |
|---|---|
not_sampled | The request fell outside the sampled percentage. Normal. |
unjudgeable | The request had nothing the judge can compare, for example a tool call only answer. |
shed | One gateway process already runs 16 shadow copies at once, so new ones are dropped to protect live traffic. Lower shadow_percentage or add replicas. |
withheld | The sampled key or team is over its own budget, the target's eval budget is spent, or the gateway could not check the budget because the database did not answer. |
Errors
| What you see | Why | Fix |
|---|---|---|
400 Not a configured auto-router: 'smart' | A name in router_names is not an auto_router/ deployment on this gateway. | Create the router under Models + Endpoints, Auto-Routers, or fix the name. |
400 api_key_ids not on this proxy: ...; pass each key's token hash, ..., team_ids not on this proxy: ... or user_ids not on this proxy: ... | A target does not exist here. Keys are named by their token hash, not the sk- value or the alias. | Copy the id from the key, team or user list. |
400 judge_model '...' is an auto-router; it must be a plain model (or baseline_model) | The judge or baseline is a router. | Pick a plain model. |
400 judge_model '...' is neither a model configured on this proxy nor a provider-qualified public model name ... | The gateway cannot call that model for the targets' teams. | Pick a model from Models + Endpoints, or a name such as anthropic/claude-sonnet-5. |
400 ... uses the Spanway SDK but required credentials are not configured: ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN | The judge or baseline would be called directly and no Anthropic credential is set. | Set the credential, or pick a model configured on the gateway. |
400 models not served by this proxy: ... | A model in models cannot be requested here, so the job would sample nothing. | Fix the model names. |
400 judge_model '...' is also an arm this job would judge: ... | The judge serves one of the compared answers. | Pick a judge that serves neither arm. |
409 Already in an active forward shadow eval job: team team-platform (job ...). Stop it first. | A target can hold one running job per direction. | Stop the running job first, or use the other direction. |
409 A requested target was claimed by another forward shadow eval job concurrently. Stop it first. | Two starts for the same target raced and the other one won. | List the jobs and stop the other one if needed. |
422 with a detail list | The body breaks a rule: no target or more than 100, baseline_model missing on a reverse job or sent on a forward one, models on a reverse job, both or neither of router_name and router_names, several routers on a reverse job, or the old max_turns field (max_turns was replaced by max_budget, ...). | Fix the field the message names. |
400 Job 3f1c2a9e-... is already completed or already stopped | The stop arrived after the job ended on its own or after another stop. | Nothing to do. The job keeps its attempts. |
403 | The key is not a proxy admin. Admin viewers may list and read jobs but not start or stop them. | Use a proxy admin key. The Admin UI hides the form and the Stop button for view only roles. |
404 No shadow eval job 3f1c2a9e-... | The id is wrong. Jobs are never deleted, so a valid id keeps working. | List jobs with GET /auto_router/shadow_eval and copy the id. |
500 DB not connected | Shadow evals store jobs and attempts in the database. | Connect a database and restart the gateway. |
| Existing evaluations could not be loaded. Refresh the page to retry. in the Admin UI | The list call failed, often while the gateway restarts. | Refresh the page. If the whole section is missing, the gateway answered 403 for your role. |
error_count keeps growing and last_error names a model | The shadow or judge call fails, for example a judge model the key may not use or a router whose tier model is down. | Pick a judge model the gateway can call and check the router's tier models under Models + Endpoints. |
Jobs, their attempts and their funnel counts are kept with no purge route. Deleting a router leaves its jobs in place.
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| ERROR | shadow_eval: funnel seed failed for job <id>: ... | The job started, but its sample counts could not be created, so the funnel counts stay empty. | Check the database. The job itself runs. |
| WARNING | shadow_eval: budget unverifiable for <leg id>, sample skipped: ... | The gateway could not read the eval spend, so it skipped the sample and counted it as withheld. | Normal during a short database outage. Check the database if it repeats. |
| WARNING | shadow_eval: spend counter increment failed for <counter key>: <error> | Redis did not take a sample's eval spend. The budget check falls back to the spend stored in the database, so the target budget can be overshot by the samples still in flight. | Check Redis. |
| ERROR | Spend tracking - shadow eval funnel drain failed | The batched funnel counts could not be written. They are retried on the next flush. | Check the database if it repeats. |
Audit
Starting a job writes a created row on Spanway_ShadowEvalJob with the job id, the targets, routers, direction, judge and baseline, sample percentage, duration, budget and end time. Stopping writes an updated row with the status before and after and who stopped it. A refused stop writes no row. See audit logs.
Related
- Cost optimisation explains the savings baseline the eval compares against and the rest of the Cost Optimization page.
- Auto routing covers creating the router you are evaluating.
- Cost Optimization page documents every control of the Shadow Evals sub tab.
- Audit logs record who started and stopped each job.
- Shadow results show each judged pair on the Evals page Shadow tab and through
GET /eval/shadow, and review queues let people check the verdicts.