Skip to main content
fallback_models is shorthand for FallbackConfig(on_error=...). When the primary model raises an eligible ModelProviderError, Agno tries the fallback models in order until one succeeds. Install both provider integrations and set OPENAI_API_KEY and ANTHROPIC_API_KEY before running the examples:
Model strings work for the primary and fallback models:
Fallbacks catch model-provider errors. Exceptions outside ModelProviderError, such as application runtime errors, propagate without trying another model.
Fallback configuration wraps calls to the agent or team leader’s primary model. It does not wrap separate reasoning_model, parser_model, or output_model calls.

Route Errors to Different Models

Agno classifies the primary error and selects one fallback list: Context-window errors are detected from ContextWindowExceededError or recognized error-message patterns. Other 4xx errors, including 400, 401, 403, 404, 413, and 422, are not routed through on_error. If every model in the selected list raises ModelProviderError, Agno re-raises the original primary-model error. The list is selected once from the primary error. A later fallback failure does not select a different error-specific list.

Retries and Fallback

Each model applies its own retry settings before its failure reaches the fallback layer:
retries=3 allows up to four primary attempts: the first attempt and three retries. The fallback allows up to three attempts with retries=2. Retries apply only to retryable errors. Context-window errors and non-retryable client errors skip the remaining retry loop. An eligible context-window error can therefore activate a fallback immediately.

Streaming

Fallbacks also wrap streaming model calls. When the primary model activates a fallback, Agno resets the accumulated response content before processing the first fallback’s chunks.
A mid-stream failure can occur after primary-model or fallback-model chunks have reached the consumer. Those emitted chunks cannot be retracted. If one fallback emits chunks and then fails, Agno does not reset accumulated content before trying the next fallback. The completed run can therefore combine partial output from the failed fallback with output from the successful fallback. Treat streamed output as provisional, or use a non-streaming run when failover must produce one atomic response.

Fallback Callback

Use callback to record which fallback completed the request:
The callback runs after a fallback succeeds. For streaming calls, it runs after the fallback stream completes. Callback exceptions are ignored so they do not interrupt a successful fallback.

Teams

Fallback configuration on a Team applies to the team leader’s model calls. Configure member agents separately when they also need fallbacks.

Parameters

Available on Agent and Team: FallbackConfig fields:

Developer Resources