Skip to main content

Module failover

Module failover 

Source
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 within HEADERS_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): after BREAKER_THRESHOLD such failures in a row a provider is skipped for BREAKER_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 as model_failover progress.

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.
FailedModel
A model left during a call, and why.
FailoverModel
A chat model that tries its candidates in order (see the module docs). request.model is replaced by each candidate’s model.
FailoverReport
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 error moves a call on to the next candidate. A rate limit does only when no retry of the node follows (last_attempt).