Overview
LiteLLM provides robust fallback mechanisms to ensure high availability of your LLM applications. When a model fails or is unavailable, LiteLLM automatically retries with fallback models or deployments.How Fallbacks Work
Fallbacks execute in order when:- API returns an error (rate limit, timeout, service unavailable)
- Model deployment is down
- Context window is exceeded
- Content policy violations occur
Basic Fallback Configuration
Single Model Fallback
Router Fallbacks
The Router provides advanced fallback logic across multiple deployments:Fallback Types
1. Default Fallbacks
Apply to all models globally:2. Model-Specific Fallbacks
Define fallbacks per model:3. Context Window Fallbacks
Automatic fallback when context window is exceeded:4. Content Policy Fallbacks
Fallback when content policy violations occur:Advanced Fallback Configuration
Fallback with Custom Parameters
Pass different parameters to fallback models:Controlling Fallback Behavior
Fallback Policies
Allowed Fails Policy
Control when a deployment enters cooldown:Deployment Cooldown
When a deployment fails multiple times, it enters a cooldown period:During cooldown, the deployment is excluded from routing but can still be used as a last resort if all others fail.
Async Fallback Support
Fallbacks work with async operations:Monitoring Fallbacks
Tracking Fallback Usage
Response Headers
Fallback information is included in response headers:Best Practices
Fallback Strategy Recommendations
- Order by capability - Place most capable/expensive models first
- Consider cost - Fallback to cheaper alternatives when appropriate
- Mix providers - Diversify across OpenAI, Anthropic, Google, etc.
- Test thoroughly - Verify fallbacks work as expected
- Monitor cooldowns - Alert when deployments enter cooldown
- Set reasonable limits - Balance availability vs. cost
Common Patterns
High Availability Pattern
Cost-Optimized Pattern
Error Handling
Related Features
- Retries - Configure retry behavior before fallback
- Load Balancing - Distribute load across deployments
- Cost Tracking - Monitor costs across fallbacks
- Logging - Track fallback events