How the VisionCoder LLM API gateway routes and fails over: how a request picks a route, how a session stays on one route, how failures switch over, how unhealthy routes are circuit-broken and restored, and why failed requests with no output are free.
Behind every model are routes from several suppliers. This page explains how the gateway scores and picks routes, how a session stays on one route, how failures switch over, and how unhealthy routes are circuit-broken and restored. Values marked as defaults can be adjusted by the platform.
First it filters: only routes open to your workspace, whose channel and model both support the request protocol and whose capabilities fit the request (a request with images drops routes without image support, an over-long prompt drops routes with too little context), minus any that are circuit-broken.
Then it layers: routes sit in a primary, a backup and a fallback tier. Selection starts in the primary tier and spills over to the backup tier, then the fallback tier, only when the whole tier is broken or full.
Within a tier it picks at random weighted by score. The score comes from success rate, speed, cost and headroom, so traffic is never piled onto one route. You can choose a call preference on the API key: speed first, balanced or cost saving.
The gateway only forwards between these routes and does no protocol conversion: a protocol the model does not declare gets a 400 that names the paths it supports.
The session identifier is taken from the client when it sends one (metadata.user_id in Claude Code, prompt_cache_key in Codex and others); otherwise it is derived from the system prompt plus the first turn, scoped to your API key.
The first request of a session picks a route by score and remembers it. As long as that route stays healthy and is not full, later requests keep using it, so the upstream context cache keeps hitting, which is cheaper and faster.
It moves only when the route gets clearly worse: at once when at least 20 samples in the last 5 minutes show a success rate below 90%, and also when the first token becomes clearly slower for a sustained period. The new route becomes the new memory.
The memory is kept for 30 minutes by default, renewed on use. It is used only for picking a route; losing it costs one cache miss and does not affect the call.
Switching happens only before the first byte reaches you: a connection failure, an upstream 5xx, an upstream 429, a first-token timeout, or a 2xx that is really an empty response or an error body all move the request to the next route.
One request normally tries up to 4 routes, each time preferring a different upstream account and supplier channel; when all of them fail you get an error: most often a 503 “no healthy model channel”, or a 429 with Retry-After when every route is rate limited upstream.
A parameter error and other 4xx would fail the same on any route, so it is not retried and the error is returned as is.
Once the first byte is sent there is no switching: on failure the stream ends with an error event in the protocol’s format, and what was already produced is settled as usual.
When the first byte is slow to arrive, the gateway sends the request to the next candidate as well and uses whichever answers first; this rescue has a per-model budget and applies only to requests that are really stuck.
Breaking works per route and protocol: if the chat protocol of a route has a problem, its responses protocol and other models on the same channel are unaffected.
By default, three consecutive real failures (5xx, timeouts, connection errors) trip the breaker, and one success resets the count; at least 10 samples in the last 5 minutes with a success rate below 50% trips it too. Client 4xx does not count.
The breaker stays open for 15 seconds by default, doubling after each failed probe up to 2 minutes. After the cooldown only a little traffic probes the route, it is restored only if the probe succeeds, and traffic then returns by score at once.
An upstream 429 or 529 does not count as a breaker failure: the route cools down for the Retry-After the upstream gives (5 seconds by default when the upstream gives none, at most 60) and the request goes to another route.
When the upstream returns 401, 402 or 403 (invalid credential, unpaid account), every model on that channel account is taken out together until the credential is replaced.
Gateway replicas share the breaker state. Platform operations can also break or restore a route by hand, which requires a reason and is recorded.
A request reserves credit once and settles once, on the attempt that succeeded; the cost of failed attempts in between is absorbed by the platform and not billed to you. A failed request with no output is not charged, and output already produced is charged by actual usage.
The exact rules for each case are under “Failed calls are free” on the billing rules page.