Tera Router
Concepts

Routing & Resilience

How the router picks targets, sweeps through backups, and keeps requests going.

Decision order

For every request, the router:

  1. Translates model following the order in Models & routing: chain:<name> → alias → provider/model → plain name. The result is an ordered list of targets.
  2. Checks access — key ∩ plan allowlist, and active budgets.
  3. Picks an account — following the provider's account strategy, skipping accounts that are cooling down or disabled. The other accounts stay as fallbacks.
  4. 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):

StrategystrategyBehavior
Router defaultdefaultFollows Settings → Routing: round robin with the global sticky limit when provider round robin is on, fill first when it is off.
Fill firstfill-firstThe highest-priority healthy account takes everything until it is unavailable.
Round robinround-robinEach account takes sticky_limit requests, then the next one takes over.
Smart round robinsmart-round-robinNew 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

EventRouter 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 requestChat requests try that account last for 30 seconds; a smart round robin conversation moves to the account that worked
429 from upstream30-second account cooldown, honor Retry-After
Upstream authentication failed5-minute account cooldown
Upstream 402, no balance or suspendedAccount disabled, next account tried
All targets exhausted503 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.

On this page