Routing & Resilience
How the router picks targets, sweeps through backups, and keeps requests going.
Decision order
For every request, the router:
- Translates
modelfollowing the order in Models & routing:chain:<name>→ alias →provider/model→ plain name. The result is an ordered list of targets. - Checks access — key ∩ plan allowlist, and active budgets.
- Picks an account — following the provider's account strategy, skipping accounts that are cooling down or disabled. The other accounts stay as fallbacks.
- Forwards the request — and moves up to the next target if it fails.
Account strategy
Each provider decides how its accounts share requests (Providers → pick a provider → Routing → Account strategy, or PUT /v1/providers/:slug/routing):
| Strategy | strategy | Behavior |
|---|---|---|
| Router default | default | Follows Settings → Routing: round robin with the global sticky limit when provider round robin is on, fill first when it is off. |
| Fill first | fill-first | The highest-priority healthy account takes everything until it is unavailable. |
| Round robin | round-robin | Each account takes sticky_limit requests, then the next one takes over. |
| Smart round robin | smart-round-robin | New conversations rotate (every sticky_limit of them); every later turn of a conversation stays on the account it started on, until it is quiet for affinity_hours. |
Smart round robin recognizes a conversation by the session id the client sends (Claude Code's metadata.user_id, Codex's prompt_cache_key), otherwise by its opening: the system prompt plus the first user message, per API key. Keeping a conversation on one account keeps the provider's prompt cache warm. Rotation state lives in memory, so a restart starts every provider from its first account again.
Fallback chains
A chain determines who gets tried next. Example heavy-coding: Claude first, GPT-4o second, OpenRouter as the closing fallback. If the first step gets a 429, the router starts a 30-second cooldown for that account and immediately continues to the second step — the client sees no error.
Every step can be switched off individually (Chains → edit → step switch, or "active": false in the API). Inactive steps are skipped but keep their place, so switching one back on restores the original order.
Retries and cooldowns
| Event | Router action |
|---|---|
| Transient issue (5xx, network) | Retry on the same account, up to 2x (500 ms, 1 s delays) |
| Account kept failing, another account of the provider served the request | Chat requests try that account last for 30 seconds; a smart round robin conversation moves to the account that worked |
429 from upstream | 30-second account cooldown, honor Retry-After |
| Upstream authentication failed | 5-minute account cooldown |
Upstream 402, no balance or suspended | Account disabled, next account tried |
| All targets exhausted | 503 to the client |
At most 10 attempts per request in total. Cooldowns rest problem accounts instead of hammering them again — their status is visible on the Provider Health page.
Beyond chat
Web search/fetch, audio, image, and embedding requests go through the same pipeline: key and plan allowlists, budgets, account priority, cooldowns, and fallback to the next target or account. Embedding tokens are metered and priced like chat tokens.
Concurrency
The gateway limits in-flight requests globally (100). When full, new requests get a 503 — more honest than an ever-growing queue. The rpm/tpm/concurrent limits on plans are stored in the schema but not yet enforced by the gateway.
Metering
Every request is recorded: the provider and model that actually served it, key, account, client type (detected from the User-Agent — Claude Code, Cursor, Codex, Cline, Copilot, Aider, etc), tokens per category, cost, cache hits, latency, and TTFT. That's exactly what you see on the Usage page.
First-token latency
TTFT (time-to-first-token) is measured per request — compare providers on the Usage page before deciding your chain order.