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. It does not wrap separate reasoning_model, parser_model, or output_model calls.
Route Errors to Different Models
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.Fallback Callback
Usecallback to record which fallback completed the request:
Teams
Fallback configuration on aTeam applies to the team leader’s model calls. Configure member agents separately when they also need fallbacks.
Parameters
Available onAgent and Team:
FallbackConfig fields: