Provider Fallback
When a provider fails a request, LLM API can send the same request to another provider before you see the error. It does this in two ways:
- Automatic failover is on by default. When a model is served by several providers and the one handling your request fails, LLM API retries the request on the model's next provider. No header is needed.
- Fallback policies are chains you define: an ordered list of
(provider, model) targets, sent with the X-LLM-Fallback-Policy-Id or X-LLM-Fallback-Policy header. A policy replaces automatic failover on the request that sends it, and its targets can be other models.
Either way there is no client-side retry loop and no duplicate billing on success.
At a Glance
|
Automatic failover |
Fallback policy |
| Turned on by |
Nothing: it is on by default |
X-LLM-Fallback-Policy-Id (stored) or X-LLM-Fallback-Policy (inline JSON) on the request |
| What it tries |
The same model on its other providers, in routing order |
Your targets in your order, with your trigger rules and deadline |
| Endpoints |
/v1/chat/completions, /v1/messages, /v1/responses |
/v1/chat/completions, /v1/messages, /v1/audio/speech, /v1/audio/transcriptions, /v1/videos |
| Turned off by |
X-No-Fallback: true on the request, or the organization setting |
Not sending the header. X-No-Fallback and the organization setting do not stop a policy you send |
| What it never does |
Switch to another model. Restart a stream that has started |
Cross projects. Restart a stream that has started |
Supported Endpoints
| Endpoint |
Automatic failover |
Fallback policy |
Notes |
POST /v1/chat/completions |
Yes |
Yes |
Sync and streaming |
POST /v1/messages |
Yes |
Yes |
Sync and streaming. Policy targets must serve the Anthropic Messages API; others are skipped. Also reads Anthropic's fallbacks field |
POST /v1/responses |
Yes |
No |
Sync and streaming. The policy headers are ignored |
POST /v1/audio/speech |
No |
Yes |
Text-to-speech |
POST /v1/audio/transcriptions |
No |
Yes |
Speech-to-text over HTTP, not WebSocket |
POST /v1/videos |
No |
Yes |
Job submission only |
POST /v1/decisions |
Own rules |
No |
Tries the model's providers in catalog priority order and never moves a pinned request; X-No-Fallback and the organization setting do not apply. See Decisions |
Every other endpoint, including /v1/embeddings and image generation, sends the request to one provider and returns its error as-is.
WARNING
A streamed request can move to another provider only while nothing has been sent to you. On
/v1/messages, and on /v1/chat/completions for models served over Anthropic's Messages API
(such as Claude on Anthropic, Amazon Bedrock or Azure), LLM API holds the stream until its first
content, for up to 10 seconds. An error the provider reports in that time, such as Anthropic's
overloaded_error, is handled like an error response: it moves the request when it would move a
non-streamed one, and otherwise you get it as an error status instead of a stream. Elsewhere the
stream starts with the provider's response. Once the stream has started, a failure ends it; the
request is not restarted on another provider.
Automatic Failover
When a model is served by more than one provider, LLM API sends your request to the provider that routing ranks best for it. If that provider fails, the request goes to the model's next provider, and so on until one answers or none is left. With a provider pin such as openai/gpt-4o, the pinned provider is tried first and the model's other providers follow, unless the pinned provider is unhealthy at that moment: then the request starts on another provider (see Routing).
What moves the request to the next provider:
- A server error from the provider (
5xx, including 503 and Anthropic's 529).
- A rate limit (
429).
- The provider answers that it does not serve the model (
404).
- LLM API times out waiting for the provider, or cannot connect to it.
- The provider rejects the account the request was sent on (
401, 402, 403, or a 400 saying the account cannot be used). In a project that uses only your own provider keys, that error is returned to you instead.
What is returned to you as-is: errors your request would get from every provider, such as an invalid parameter, a prompt longer than the model's context window or a content-policy refusal. A request you cancel is not retried either.
Turning it off:
- For one request, send
X-No-Fallback: true. See Routing.
- For the whole organization, switch off Automatic provider fallback in the dashboard under Organization → Settings → Policies.
Neither affects a fallback policy you send: an explicit policy always runs. Two more exceptions:
- A Claude model served on LLM API's accounts can still make one more attempt on Anthropic after the first one fails, unless the request pins another provider.
- The organization setting does not stop the reroute away from a pinned provider with low uptime;
X-No-Fallback does.
Failing Providers Leave Rotation
When you send a model without a provider prefix on /v1/chat/completions, /v1/messages or /v1/responses, a provider that keeps failing for that model is taken out of automatic failover's rotation for a while, so your requests stop paying for an attempt that will fail.
|
|
| What counts as a failure |
A 5xx response from the provider (including 503, 504 and 529, also when a held stream reports one before its first content), or a connection to it that fails before the response or that content starts. Rate limits (429), other 4xx errors and requests that run out of time without an answer do not count. |
| Threshold |
3 failed requests in a row for the same model on the same provider. |
| Cool-down |
30 seconds from the most recent failure. Requests for that model go to its other providers meanwhile. |
| Recovery |
After the cool-down, requests go to the provider again. One successful request puts it back in rotation; another failure starts a new 30-second cool-down. |
| Configurable |
No. The threshold and cool-down are the same for every project. |
- The count is per model: a provider failing one model stays in rotation for its other models.
- If every provider of the model is cooling down, the request is still sent rather than rejected.
- With your own provider keys, failures on your key take the provider out of rotation for that project only. Failures on LLM API's own accounts take it out for everyone, except projects that use only their own keys.
- Each gateway instance keeps its own count, so while your traffic is spread over several instances a few more requests can reach the failing provider before every instance skips it.
- A fallback policy keeps its target order: a target that is cooling down is still tried in its place. Its failures do count toward the provider's cool-down for automatic routing.
- A provider that answers that it does not serve the model (for example
404 model not found) is handled by a separate rule on /v1/chat/completions: after 2 such answers in a row it is skipped for that model for 60 seconds, and the pause doubles, up to 30 minutes, while it keeps refusing.
Fallback Policies
A fallback policy is a chain you define: up to 8 (provider, model) targets tried in your order, with your own trigger rules and a deadline for the whole chain. Use one when automatic failover is not what you need: to fall back to a different model, to fix the order of providers, or to fall back on audio and video requests. On a request that sends a policy, only the policy's targets are tried. On the endpoints that accept a policy, a malformed policy header or an unknown policy ID is refused with 400 invalid_fallback_policy and the reason.
Quickstart
Create a policy (once per project) on the dashboard's Fallback page with New policy. For example, set the policy ID to prod-claude, pick claude-opus-4-7 on anthropic as the first target and claude-opus-4-7 on aws-bedrock as the second (the form lists the providers that serve the model you pick), and set the chain deadline to 15 seconds. The form offers chat and video models; for audio targets, send the policy inline.
Reference it on a request:
POST /v1/chat/completions
Authorization: Bearer $LLM_API_KEY
X-LLM-Fallback-Policy-Id: prod-claude
Content-Type: application/json
{"model": "claude-opus-4-7", "messages": [...]}
Read the result headers:
HTTP/1.1 200 OK
X-LLM-Served-By: aws-bedrock/claude-opus-4-7
X-LLM-Fallback-Triggered: true
X-LLM-Fallback-Hops: 2
That request was attempted on Anthropic first, failed with a trigger error, then succeeded on AWS Bedrock.
Key Concepts
| Term |
Meaning |
| Target |
A (provider, model) pair, plus optional per-hop timeout_ms, max_attempts, backoff_ms. |
| Policy |
An ordered list of 1–8 targets, a chain-wide deadline_ms, and a trigger describing which errors advance to the next target. |
| Primary target |
The first target in the policy. It is the request's initial attempt; the rest of the chain is the fallback. |
| Hop |
One attempt against one target. The number of hops is reported via X-LLM-Fallback-Hops. |
| Trigger |
The rule for advancing to the next target. A hop's error must match trigger.classes or trigger.http_status — anything else terminates the chain. |
| Error class |
A normalized vocabulary mapping each provider's native error shape to one of rate_limited, server_error, timeout, auth_error, etc. |
| Capability gap |
A pre-hop check that skips a target lacking a feature the request needs (e.g. vision). Controlled by on_capability_gap = skip (default) or degrade. |
timeout_ms and deadline_ms do not interrupt a streamed hop (chat completions, /v1/messages, streamed text-to-speech) while it waits for its provider; deadline_ms still stops the chain from starting another hop once it has passed.
Sending a Policy
Send a policy in one of two ways. A policy travels only in an HTTP header; the one body field LLM API reads for fallback is Anthropic's fallbacks list on /v1/messages.
By reference (stored)
Reference a policy you've previously saved on the project. Best for production: centralized management, audit history, shorter request payloads.
POST /v1/chat/completions
X-LLM-Fallback-Policy-Id: prod-claude
Inline JSON
Pass the full policy JSON in the header (capped at 8 KiB). Best for ad-hoc or programmatic use.
POST /v1/chat/completions
X-LLM-Fallback-Policy: {"targets":[...],"deadline_ms":15000}
INFO
If both headers are present, the inline header (X-LLM-Fallback-Policy) wins. The conflict is
recorded on the access log entry (fallback.conflict: true) so it's visible without surfacing as
a user-facing error.
Request Validation
The body's model must match the policy's first target. The first target is the request's primary attempt — fallback is the alternate chain that runs only if the primary fails.
WARNING
Sending a policy whose first target points at a different (provider, model) than the body
declares is rejected up-front with HTTP 400, before any provider is contacted.
Example — mismatch is rejected:
POST /v1/chat/completions
X-LLM-Fallback-Policy: {"targets":[{"provider":"anthropic","model":"claude-opus-4-7"},
{"provider":"aws-bedrock","model":"claude-opus-4-7"}]}
Content-Type: application/json
{"model": "gpt-4o", "messages": [...]}
HTTP/1.1 400 Bad Request
{
"error": {
"message": "request body model \"gpt-4o\" does not match the first target of the fallback policy (\"anthropic/claude-opus-4-7\")",
"type": "invalid_request_error",
"param": "model",
"code": "fallback_policy.body_model_mismatch"
}
}
Notes:
- When
model is in provider/model form (e.g. "anthropic/claude-opus-4-7"), both fields are compared.
- When
model is a bare id (e.g. "claude-opus-4-7"), only the model id is compared.
- On
/v1/chat/completions and /v1/messages, models are compared by their catalog name, and each provider is sent its own id. A target may name its model by catalog name, alias, or that provider's own id (anthropic.claude-opus-4-7 on aws-bedrock); bedrock is accepted for aws-bedrock. The body's model is the catalog name, an alias, or provider/id (aws-bedrock/anthropic.claude-opus-4-7); a bare provider id is not a model name.
- On those endpoints, a target whose provider does not serve its model is skipped; when it is the first target, the body is not compared with it. If no target is served, the request is refused with
400 fallback_policy.unresolved_targets, naming every provider/model pair. Two targets that name the same pair are refused with 400 invalid_fallback_policy.
- Saving a stored policy refuses a pair the catalog does not serve, and a repeated pair, with
422 naming it.
- Validation runs identically whether the policy is supplied inline or by reference.
- On
/v1/messages the same rejection uses Anthropic's error format.
- A rejected request emits a
rejected_validation outcome in observability; it never counts as a provider failure or a fallback hop.
Trigger Configuration
A hop's error must match either the policy's trigger.classes set or its trigger.http_status set to advance to the next target. Any other failure (and every success) terminates the chain immediately.
trigger.classes
A normalized vocabulary mapped from each provider's error taxonomy. Omit the field entirely to inherit the safe default — request-attributable classes are never in the default and must be listed explicitly.
Default (availability errors — applied when classes is omitted):
| Class |
Meaning |
rate_limited |
Upstream 429 / quota exhausted / throttled |
server_error |
Upstream 5xx that is not a known capability or routing failure |
region_unavailable |
Region/zone outage or routing-layer failure |
model_unavailable |
Model offline, not deployed in the target region, or temporarily disabled |
timeout |
Per-hop deadline exceeded before headers (or first byte for streams) |
network_error |
TCP/TLS/DNS failure, connection reset, premature EOF |
Opt-in only (request-attributable — must be listed explicitly):
| Class |
When to enable |
auth_error |
Upstream 401/403 — only if you intentionally rotate credentials across providers |
invalid_request |
Upstream 400 with malformed request — only if downstream targets accept different schemas |
context_length_exceeded |
Prompt is too long for this model but smaller for next target |
capability_unsupported |
Feature (e.g. tools, vision) missing on primary but present on fallback |
invalid_response |
Provider returned malformed/unparseable payload |
content_policy |
Provider refused on safety grounds; alternate target may accept |
WARNING
The opt-in classes are request-attributable — the failure is caused by your request, not the
provider. Enabling them blindly can mask real bugs. Only opt in when you have a concrete reason.
trigger.http_status
A list of raw upstream HTTP status codes that also trigger fallback regardless of class mapping. Each value must be 100–599. Use this as an escape hatch when a provider's status doesn't classify cleanly.
| Status |
Typical cause |
408 |
Request timeout |
425 |
Too early |
429 |
Rate limited |
500 |
Internal server error |
502 |
Bad gateway |
503 |
Service unavailable |
504 |
Gateway timeout |
529 |
Anthropic overloaded |
Anthropic fallbacks Field
Anthropic SDKs can send a fallbacks field in the request body. On /v1/messages, LLM API accepts it and runs it itself; the field is never forwarded to the provider.
{
"model": "claude-opus-5",
"max_tokens": 1024,
"messages": [...],
"fallbacks": [{ "model": "claude-opus-4-8", "max_tokens": 2048 }]
}
"default" asks for nothing beyond automatic failover.
- A list of 1–3 entries is tried after the requested model has failed on its providers with an error that moves on (see Automatic Failover). Each listed model is tried in order on its own providers; the listed models share 8 attempts, so each gets up to 8, 4 or 2 providers when 1, 2 or 3 are listed. With automatic failover switched off for the organization, each listed model gets one provider.
- Unlike Anthropic's API, a listed model is used when a provider fails, not when the model refuses to answer.
- An entry's
max_tokens, thinking and output_config replace the request's values for that model only. speed is not supported.
- A list LLM API cannot run is rejected with
400 invalid_request_error before any provider is contacted, for example one with an unknown or repeated model, more than 3 entries, or a model your API key cannot use on /v1/messages.
- A fallback policy header takes precedence and the field is ignored.
X-No-Fallback: true also leaves it unused.
Reading the Response
Successful responses from /v1/chat/completions, /v1/messages and the audio and video endpoints carry these headers, in either mode:
| Header |
Meaning |
X-LLM-Served-By |
provider/model that answered |
X-LLM-Fallback-Triggered |
true if the request went to a target after the first, whether or not it answered |
X-LLM-Fallback-Hops |
Number of hops attempted |
On an error, /v1/chat/completions still sends all three and /v1/messages sends them when a provider answered. The audio and video endpoints send X-LLM-Fallback-Triggered and X-LLM-Fallback-Hops after a fallback policy runs out, without X-LLM-Served-By. /v1/decisions sends only X-LLM-Served-By, and /v1/responses sends none; the request log shows which provider served each request.
Example — the first provider answered:
X-LLM-Served-By: anthropic/claude-opus-4-7
X-LLM-Fallback-Triggered: false
X-LLM-Fallback-Hops: 1
Example — fallback served the response:
X-LLM-Served-By: aws-bedrock/claude-opus-4-7
X-LLM-Fallback-Triggered: true
X-LLM-Fallback-Hops: 2
When Fallback Does Not Apply
No further provider is tried, and you get the error, in these cases:
- The endpoint does not support the mode (see Supported Endpoints).
- The request is streamed and the stream has already started (see Supported Endpoints).
- Automatic failover:
X-No-Fallback: true was sent or the organization switched it off (with the exceptions above), the model has no other provider your API key can use, or the error is one your request would get from every provider.
- Fallback policy: the hop's error matches neither
trigger.classes nor trigger.http_status, or the chain deadline (deadline_ms) elapsed before the next hop could begin.
Best Practices
- Let automatic failover handle provider outages. Send a policy when you need something it does not do: a different model, a fixed provider order, or fallback on audio and video.
- Pair the same model across providers for true drop-in fallback (e.g.
anthropic/claude-opus-4-7 → aws-bedrock/claude-opus-4-7). Cross-model fallback works but may change response quality or pricing.
- Keep
deadline_ms realistic. If your client times out at 30s, a chain deadline of 25s is sensible. Too tight, and the second hop never runs.
- 2–3 targets is the sweet spot. The maximum is 8, but deeper chains amplify the chance that the chain-wide
deadline_ms elapses before a healthy hop is reached.
- Start with the default trigger classes. Only opt into request-attributable classes (e.g.
auth_error, content_policy) when you have a specific reason — they can mask bugs you'd otherwise see.
- Use stored policies in production. Inline policies are great for testing, but stored policies give you centralized updates, audit history, and shorter request payloads.
- Inspect
X-LLM-Fallback-Triggered in your monitoring. A sudden spike means your primary is degrading — fallback is doing its job, but it's also a signal worth alerting on.
FAQ
Do I need a header to get fallback?
No. Automatic failover across a model's providers is on by default on `/v1/chat/completions`, `/v1/messages` and `/v1/responses`. A fallback policy header is only needed for your own chain, such as a fallback to a different model or fallback on audio and video requests.
Can I embed the policy in the request body?
No. A policy travels only in the two HTTP headers (`X-LLM-Fallback-Policy-Id` and
`X-LLM-Fallback-Policy`), the single transport across every supported endpoint, including the
binary/multipart audio and video routes where mutating the body would be costly. On
`/v1/messages` you can instead list fallback models in Anthropic's
[`fallbacks`](#anthropic-fallbacks-field) field.
What happens if I send both headers?
The inline header (`X-LLM-Fallback-Policy`) wins. The conflict is recorded on the access log
entry (`fallback.conflict: true`) so it's visible without surfacing as a user-facing error.
Can a policy in project A reference a policy id stored in project B?
No. Stored policies are scoped to a single project; cross-project ids resolve to a 404-shaped
not-found error. This is deliberate — it makes project-membership probing impossible.
Does fallback restart a streaming response after some tokens have been delivered?
No. Once the stream has started (see [Supported Endpoints](#supported-endpoints)), the request
stays on that provider. A later upstream failure ends the existing stream; there is no second
start.
Why isn't /v1/embeddings supported?
Embeddings from different models occupy different vector spaces (and often different
dimensions). Silently swapping the producing model would corrupt the caller's vector store.
Until a "compatible alternates" concept exists, embeddings stay single-shot.
What's the cache TTL on stored policies?
60 seconds, positive **and** negative. Admin mutations publish an invalidation event over Redis
pub/sub so all gateway replicas drop their cached entry immediately — you don't have to wait the
full TTL after a `POST`/`PUT`/`DELETE`.
After how many errors does LLM API stop sending requests to a failing provider?
After 3 failed requests in a row for the same model, the provider is skipped for that model for
30 seconds, then tried again. The values are fixed and cannot be configured. See [Failing
Providers Leave Rotation](#failing-providers-leave-rotation).
Is there a hard ceiling on chain depth?
Yes — 8 targets. In practice 2–3 is the sweet spot; deeper chains amplify the chance that the chain-wide `deadline_ms` elapses before a healthy hop is reached.