This page describes features extending the AI Gateway, which provides a unified API for accessing multiple AI providers. To learn more, see AI Gateway.
Quick Start
Automatically retry failed requests with different providers or models.Configuration
| Parameter | Type | Required | Description | 
|---|---|---|---|
| fallbacks | Array | Yes | List of fallback models in order of preference | 
| model | string | Yes | Model identifier for each fallback | 
Trigger Conditions
Fallbacks activate on these errors:| Error Code | Description | Auto-retry | 
|---|---|---|
| 429 | Rate limit exceeded | ✅ Yes | 
| 500 | Internal server error | ✅ Yes | 
| 502 | Bad gateway | ✅ Yes | 
| 503 | Service unavailable | ✅ Yes | 
| 504 | Gateway timeout | ✅ Yes | 
| 400 | Bad request | ❌ No | 
| 401 | Unauthorized | ❌ No | 
Best Practices
Fallback Chain Design:- Use a maximum of 3 Fallback models for performance.
- Order fallbacks by preference/cost.
- Use models with similar capabilities.
- Include fast backup option.
Code examples
Troubleshooting
**Fallbacks not triggering- Check error codes match trigger conditions
- Verify fallback models are available
- Ensure API keys are configured for all providers
- Reduce number of fallbacks (max 3)
- Set appropriate timeouts
- Use faster models in fallback chain
- Failed requests may still incur charges
- Monitor fallback usage rates
- Optimize primary model selection
Monitoring
Track these metrics for optimal fallback performance:- Fallback trigger rate: % of requests using fallbacks
- Success rate by position: Which fallbacks succeed most
- Cost impact: Additional charges from fallback usage
- Latency increase: Time added by fallback attempts
Limitations
- Response consistency: Different models may return varying output styles
- Parameter support: Not all providers support identical parameters
- Cost implications: Failed requests may still incur charges from primary provider
- Latency impact: Sequential attempts add processing time
- Provider dependencies: Requires API keys for all fallback providers