Routing mechanics

How a request picks an upstream

API Token Router is a routing and billing layer, not a model. Every call follows the same path: authenticate the key, resolve the catalog model, walk the upstreams that speak the same protocol, and bill the tokens that came back. This page describes the mechanics plainly.

Updated 2026-11-23 (UTC) · data window 2026-11-22 to 2026-11-23

What happens on each request

  1. Key and balance check. The gateway authenticates the API key, resolves the organization behind it and, for paid models, checks the available balance before contacting an upstream. A rejected key or an exhausted balance never reaches a model.
  2. Model and protocol resolution. The model id is looked up in the live catalog. The incoming endpoint decides the protocol: /v1/chat/completions speaks OpenAI Chat Completions, /v1/messages speaks Anthropic Messages, and the native Google routes speak Gemini generateContent. Same-protocol calls pass through unchanged; cross-protocol calls are translated in both directions.
  3. Chain construction. The router builds an ordered chain from the upstream channels configured for that model and protocol. Channels that lack credentials, are marked unavailable, or speak a different protocol are skipped instead of being tried blindly.
  4. TTFB budget. The first attempt gets a time-to-first-token budget covering connect (including DNS and TLS) and response headers. If headers do not arrive in time, the attempt is classified as a timeout. Once headers arrive, the body streams without that header deadline.
  5. Classification and retry. Upstream responses are sorted into rate limit (429), server error (5xx), timeout and client error (other 4xx). Retryable failures are retried on the same channel for up to two attempts, with exponential backoff and jitter; when the chain has another compatible channel, the loop can advance to it. Client errors are returned immediately and do not count against the channel.
  6. Circuit breaking. Repeated retryable failures from one channel open its circuit, taking it out of rotation for a cooldown. After the cooldown the circuit goes half-open and only returns the channel to full rotation after successful probe requests.
  7. Fallback and final error. If a channel stays open or keeps failing, the request moves to the next compatible channel in the chain. If every channel is exhausted or circuit-open, the caller gets an explicit error instead of a hang.
  8. Billing. Once a response is accepted, token usage is priced against the catalog snapshot active at request time. The pricing file is re-read when it changes, so the next request uses the new price without a redeploy. One key and one USD balance cover every model family.

Health checks never spend quota

Channel health comes from free GET /v1/models probes. A probe asks an upstream which models it serves; it never sends a completion request, so monitoring cannot consume tokens or spend upstream quota. Keys whose last probe failed are left out of the routing pool until they recover.

What we do not do

  • No training on your request content. We do not use prompts or completions sent through the gateway to train models.
  • No silent model substitution. If the model you requested cannot be served, the request fails with an explicit error. A different model is never swapped in behind the same response.
  • No completion requests for health checks. Probes stop at the model list, which is why they cost nothing in upstream quota.

FAQ

Does a retry cost me twice?

No. Billing follows the token usage returned by a successful response. An attempt that fails before returning usage is not billed, and a completed request is recorded once against your key. Current prices are on the model catalog.

What happens when every upstream for a model is circuit-open?

The gateway returns an explicit error instead of queueing forever or substituting another model. Failing channels stay out of rotation until a half-open probe succeeds. The buying guide explains how this differs from a single reseller.

Can I use the gateway alongside direct vendor accounts?

Yes. Many teams keep a direct account for contractual workloads and route experimentation, burst capacity or multi-model agents through one key here. Costs and trade-offs are compared on the compare page.