Skip to main content
Pass fallback_models to any Agent or Team. If the primary model fails after exhausting its retries, each fallback is tried in order until one succeeds.
If gpt-4o fails after exhausting its own retries, Claude is tried automatically. Model strings work too:

Usage with Teams

Fallback models apply to the team leader’s model calls. Member agents keep their own models and are not affected by the leader’s fallback config.

Error-Specific Fallbacks

FallbackConfig lets you route different error types to different fallback models. Instead of a flat list, you specify which models to try for rate limits, context window overflows, and general errors separately.

Error routing

When the primary model fails, the error is classified and routed to the matching fallback list: If a specific list (like on_rate_limit) is empty, on_error is used as a catch-all. Non-retryable client errors like 400, 401, 403, 404, and 422 are not caught by fallback. These indicate configuration problems (bad API key, invalid request) that need to be fixed rather than masked by switching models.

Fallback Callback

Use the callback parameter to get notified whenever a fallback model is activated. This is useful for logging, metrics, or alerting.
The callback fires after the fallback model succeeds. For streaming calls, it fires after the full stream completes.

Retry vs. Fallback

Retry and fallback are separate layers. Retry happens inside each model. Fallback only triggers after the primary model’s retry loop is fully exhausted.
Each model controls its own retry behavior:
The primary model retries 3 times with exponential backoff. Only after all 4 attempts (the initial call plus 3 retries) fail does the fallback kick in, and it gets 2 retries of its own.

Streaming

Fallback works with streaming responses. If the primary model fails mid-stream, the fallback model takes over and the response content is reset so the consumer receives a clean response from the fallback model only.

Parameters

Available on both Agent and Team:

FallbackConfig

Developer Resources