Skip to content

Canary routing

Last updated: 2026-11-26T03:21:52-03:00 (UTC-3)

A canary sends a share of an alias’s traffic to one new target while the rest stays on the targets you trust, keeps each key or session on its side, can copy traffic to a shadow target whose answers are thrown away, rolls back automatically when the canary misbehaves, and keeps every saved version of the alias so you can roll back in one click. Promotion is always a human save.

Four flags, all off by default:

Flag Kind What it turns on
canary_routing model policy (plan right) The split of an alias with a canary policy
canary_shadow operator, requires canary_routing Shadow copies (canary.shadow)
canary_auto_rollback operator, requires canary_routing Automatic rollback (canary.auto_rollback)
routing_versions operator, requires admin_model_editor and PostgreSQL Versioned alias configuration with rollback

This is the gateway’s own canary between provider targets. Canaries of the gateway release itself (Argo Rollouts, Flagger, a mesh) stay with your delivery tool; the N-1/N upgrade test covers two releases on one database.

features:
canary_routing: true
canary_shadow: true
canary_auto_rollback: true
routing_versions: true
models:
- id: chat
capabilities: [chat]
targets:
- {provider: primary, model: gpt-4.1-mini} # 0: stable
- {provider: primary, model: gpt-5-mini} # 1: canary
- {provider: lab, model: candidate-2026-11} # 2: shadow
canary:
target: 1
percent: 10
sticky: key # key (default), session or request
shadow:
target: 2
percent: 50
max_concurrency: 4
auto_rollback:
min_requests: 20
max_error_rate: 0.2
max_latency: 4s
window: 5m
Field Values Default
canary.target index of the canary target in targets required
canary.percent 0 to 100: the share of keys, sessions or requests on the canary side required
canary.sticky key, session (the session header, else the key) or request (a new draw each request) key
canary.header session header (sticky session only): 1 to 64 letters, digits or dashes, never a credential or hop-by-hop header X-Gateway-Session-Id
canary.shadow.target index of the shadow target, not the canary required with shadow
canary.shadow.percent 1 to 100: share of eligible requests copied 100
canary.shadow.max_concurrency 1 to 64 copies in flight for the alias, per replica (64 for every alias together) 4
canary.auto_rollback.min_requests 5 to 10,000 canary outcomes in the window before a decision 20
canary.auto_rollback.max_error_rate 0.01 to 1 0.5
canary.auto_rollback.max_latency 1ms to 10m mean header latency of buffered answers; unset means latency never triggers unset
canary.auto_rollback.window 1m to 1h 5m

At least one target must stay stable (neither canary nor shadow), and the canary and shadow targets need a provider and model that no other target of the alias uses (routing tells targets apart by provider and model, so a “same model, new parameters” canary needs its own provider connection). The policy cannot combine with auto_route, passthrough or a wildcard alias. In the console it lives in the model editor (Model catalog → Edit routing → Canary); the API is the model PUT with the canary object. The policy is validated even with the flags off.

  • The side is drawn once. With sticky: key (or session), the side comes from an HMAC of the organization, team, key, alias and session value, keyed by the deployment (see keyed pin IDs): every replica draws the same side for the same key, with no shared state. A key stays on its side while the percent holds; raising the percent only moves more keys to the canary. With sticky: request each request is drawn at random.
  • The stable side never reaches the canary or the shadow. The split removes those targets from the candidates before any strategy runs, the way tag routing does: weights, latency routing, adaptive order and affinity work inside the side as usual.
  • The canary side tries the canary first, then falls back to the stable targets in their usual order. Fallback, retries, circuit breakers, admission limits and budgets are unchanged.
  • A continuation (a Responses request with previous_response_id or a conversation) is not split, whatever the flag: it keeps every target except the shadow, so it reaches the provider holding its state; when that provider is not a candidate the answer is 409 continuation_target_unavailable. Other single-send calls (native skills, hosted tools) are split like any request.
  • With canary_routing off, an alias with a policy routes to its stable targets only. Turning the flag off is the kill switch.
  • If tag routing or target conditions leave no target on the request’s side, the answer is 503 no_eligible_target.

Applies to Chat Completions and the routes translated through it, the native operation routes (Messages, Responses, embeddings, moderations, rerank, images and the others) and native Gemini generateContent.

With canary_shadow, a sample of eligible requests is copied in the background to the shadow target:

  • Eligible: stateless Chat Completions, embeddings, moderations, rerank, Messages and Responses sent by a client; Responses only with "store": false, so no stored response is left at the shadow provider. No copy starts while the replica drains. Never stateful calls (continued Responses, native skills), images, audio, video, files, batches or realtime, and never the gateway’s own internal calls.
  • The copy is the client’s body, sent as the same key to the same route, with only the anthropic-version, anthropic-beta and openai-beta headers; no idempotency key, session or tag header. It runs the alias pipeline again (guardrails, budgets, quota) and reaches only the shadow target, once.
  • Never affects the caller. It starts after the caller’s request was admitted and routed, runs on its own context with the alias’s request timeout (at most 10 minutes), and its answer is discarded. It reads and writes no exact, semantic or chat answer cache, makes no fallback, capture or affinity pin, and is not counted against the caller’s RPM.
  • Charged and logged as shadow. Its usage is recorded and charged to the same key, team and attributed customer, with the usage tag shadow=true (source gateway with tag provenance) and the request ID <request>-shadow. It counts against budgets, TPM and TPD like any request of the key (only RPM and per-model rate limits leave it out), so a key near its token limit should not be shadowed at a high percent. The gateway’s own nested calls of a copy (guardrails, summaries) are ordinary internal calls.
  • Bounded. Past max_concurrency copies of the alias (or 64 in all) a copy is dropped and counted.

With canary_auto_rollback, every outcome of the canary target counts: transport failures, 401, 403, 408, 429 and 5xx are failures (as for adaptive routing), and buffered successful answers give a header latency. Once the window holds min_requests outcomes, a failure share above max_error_rate or a mean latency above max_latency rolls the canary back:

  1. On that replica the canary percent becomes 0 at once: new requests go to the stable side.
  2. With routing_versions and PostgreSQL, the gateway saves the alias with percent: 0 as a routing version (source: auto_rollback, actor system:canary_auto_rollback, audit action model.auto_rollback), so every replica and the console follow. The write uses the configuration version, so a concurrent human save or another replica’s rollback wins and this one stops (rollback_stored: stored once the live alias shows percent 0, superseded, conflict, failed, file_owned when the GitOps file owns the alias, or local without the store).

Raising the percent again, or making the canary the stable target, is a normal save by a person.

A team can also roll the canary back on quality: a route experiment with guarded rollback scores both sides with one of its evaluators and uses this same rollback (reason evaluation_pass_rate) when the canary’s pass rate falls more than max_drop points below stable. It only acts on an alias that has auto_rollback here and lists the experiment’s team in auto_rollback.evaluation_teams (at most 64 team IDs; empty, no team may).

With routing_versions, every console or API save of an alias records the saved model as an immutable version (migration 187, gateway_routing_versions), in the same transaction as the save. The first versioned save of an alias also records the model it replaced as version 1 (baseline). The newest 50 versions are kept per alias.

  • GET /api/v1/admin/models/{id}/routing-versions (models:read) lists them, newest first: version, source (baseline, save, rollback, auto_rollback), actor, request ID, configuration version, time and the stored model.
  • POST /api/v1/admin/models/{id}/routing-versions/{version}/rollback with {"version": <configuration version>} (models:manage, CSRF) saves that version’s model again as a new version (source: rollback, rolled_back_from). It goes through every check of a model save: permissions, license, GitOps file ownership, validation and the configuration version (409 when it changed). The audit action is model.rollback.
  • In the console: Model catalog → Edit routing → Routing versions, with Roll back to vN on each earlier version.

GET /api/v1/admin/routing-status (global providers:read) adds canary_routing and canary: per alias, the configured and effective percent, stickiness, stable and canary outcomes and failures, the window’s outcomes, failures and mean latency, whether it rolled back (when, why, whether it was stored), and the shadow counters (sent, answered, failed, dropped at the bound, sampled out, not eligible, in flight). The console shows them in Providers → Routing & destination capacity → Canary routing. With Prometheus, /metrics adds gateway_canary_requests_total{side="stable"|"canary"}, gateway_canary_rolled_back and gateway_canary_shadow_total{result="sent"|"dropped"|"failed"}, with no alias, key or tenant label.

  • Counters, the rollback window and shadow bounds are per replica. The side of a key is the same on every replica that shares the provider encryption key (or the session signing key); without either key each replica draws its own sides, and during a provider-key rotation replicas on the old and new key can disagree until all restarted.
  • Routing versions record console and API saves and rollbacks while routing_versions is on; deletes, GitOps applies and saves made with the flag off are not versions, so the version before the newest is not always the state right before it. Rolling back a deleted alias creates it again.
  • A rollback is replayed through the model PUT, so it appears as two requests in the request log and metrics.
  • A local rollback without the store lasts until the policy changes.
  • Rotating the provider encryption key redraws every key’s side once.
  • Shadow copies add load and cost on the shadow target and run the guardrails again; size percent and max_concurrency accordingly.

Migration 187 adds gateway_routing_versions. An older binary ignores the table and refuses the canary field and the four flags: remove the canary policies and the flags before rolling back.

m7gtw[email protected]