Expand description
Failing over to fallback models when a provider is down.
A node’s model may list fallbacks, tried in order when a call fails for
a reason of the provider’s infrastructure:
model:
provider: openai
name: gpt-4o-mini
fallbacks:
- { provider: azure-openai, name: gpt-4o-mini } # deployment name
- { provider: anthropic, name: claude-haiku-4-5 }- What fails over (
fails_over): server errors (5xx), network errors (connection refused, TLS, timeouts, a stream cut before its first token) and a provider that does not answer withinHEADERS_TIMEOUT. A rate limit (429) fails over only on the node’s last attempt, after the node’s own retries (retry.max_retries) are spent. Authentication, invalid requests, context length and content filtering never fail over: the caller gets that error, naming the model that gave it. - Streaming: a candidate is only left before it streamed its first token (text, reasoning or a tool call). An error after that is the call’s error, so nothing the user already saw is answered twice.
- Circuit breaker (
Breakers): afterBREAKER_THRESHOLDsuch failures in a row a provider is skipped forBREAKER_COOLDOWN, then tried again (one success closes it). The last candidate is always tried. - Report: the stream of a call that did not end at the first candidate
starts with
ChatDelta::Failover, naming the model that answered and why each one before it was left (error texts are the providers’ own, already scrubbed of credentials). Nodes charge the response at the price of the model that answered and report it asmodel_failoverprogress.
Structs§
- Breakers
- Per-provider circuit breakers, shared by every clone of a
crate::ModelRegistry(so by every run of a process). - Candidate
- One model a call may be made with.
- Failed
Model - A model left during a call, and why.
- Failover
Model - A chat model that tries its candidates in order (see the module docs).
request.modelis replaced by each candidate’s model. - Failover
Report - Which model answered a call that failed over, and the ones left before it.
Constants§
- BREAKER_
COOLDOWN - How long a provider is skipped once its breaker opened.
- BREAKER_
THRESHOLD - Failures in a row after which a provider is skipped.
- HEADERS_
TIMEOUT - How long a candidate with a fallback after it may take to answer a request (its response headers) before the next one is tried. Streamed tokens may take longer: reasoning models think before the first one.
Functions§
- fails_
over - Whether
errormoves a call on to the next candidate. A rate limit does only when no retry of the node follows (last_attempt).