What a fallback chain is
A fallback chain is the ordered list of model providers a request may be sent to. The gateway sends the request to the first provider in the chain. If that provider fails in a way that is worth another try, the gateway sends the same request to the next one, up to the key’s attempt limit. The chain for a request is built from three things:- The key’s routing setting: no fallback, fall back to all eligible providers, or a routing policy.
- The requested model: only providers that can serve the model stay in the chain. A request for
claude-sonnet-4-5is never sent to an OpenAI credential. - The key’s provider access and budgets: a provider the key is not allowed to use, or whose provider-scoped budget is exhausted, is removed.
Routing settings on a key
Open the key under AI Gateway, Virtual Keys and click Edit. The Routing section lists two fixed choices, then one row per routing policy the key can reach:
The attempt limit is 3 by default and is part of the key’s configuration (
fallback.maxAttempts on the management API). With no fallback the limit is 1.
What triggers a fallback
The gateway decides from the provider’s real answer, and this is not configurable.
When every attempt fails, the caller gets the error of the last provider tried, with that provider’s status and body.
Streaming
For a streaming request the gateway falls back only while opening the stream. Once the first bytes reach the caller, a provider failure ends the stream with anevent: error frame. Chunks from two providers are never spliced into one response.
What the caller sees
The response carriesX-LangWatch-Fallback-Count with the number of failovers that happened, and only when it is at least 1. A request served by the first provider has no header.
gateway_provider_attempts_total{credential_id, outcome} and every failover in gateway_fallback_events_total{from_credential, to_credential}.
Circuit breaker
Each provider credential has a circuit breaker. After 10 failures inside a 30 second window the breaker opens and the gateway skips that credential for 60 seconds, then lets one probe request through. A 5xx, a timeout or a connection failure counts as a failure; a 429 or a terminal 4xx does not. The window decides: the same ten failures spread over more than 30 seconds leave the breaker closed. A skipped credential does not consume an attempt. When the breaker is open on every credential in the chain the caller gets503 circuit_open with the message provider temporarily unavailable: repeated upstream failures opened the circuit breaker, retry shortly.
The window, the threshold and the open duration are gateway settings: LW_GATEWAY_CIRCUIT_WINDOW_S, LW_GATEWAY_CIRCUIT_THRESHOLD, LW_GATEWAY_CIRCUIT_COOLDOWN_S. gateway_circuit_state{credential_id} reports 0 closed, 1 open, 2 half-open, and is the only view of the breaker state. A skipped attempt is counted as outcome="circuit_open" in gateway_provider_attempts_total.
Errors before the first attempt
Boundaries
- The gateway sends each attempt to one credential. Requests are not spread across several credentials of the same provider.
- Which failures trigger a fallback is fixed. A per-key trigger list does not exist.
- A fallback to a different vendor sends the prompt to that vendor. Use a routing policy or provider access to keep a key inside one vendor.