Fallbacks
Fallbacks allow the SDK to automatically retry with alternative models when the primary model fails due to infrastructure issues.How Fallbacks Work
Configuring Fallbacks
Per-Request Fallbacks
Global Fallbacks
Configure fallbacks at the client level:Combining Both
Per-request fallbacks override global fallbacks:What Triggers Fallback
Fallbacks are triggered by infrastructure errors that might be resolved by trying a different provider:| Error | Code | Triggers Fallback |
|---|---|---|
| Rate Limit | 429 | Yes |
| Server Error | 5xx | Yes |
| Service Unavailable | 503 | Yes |
| Gateway Timeout | 504 | Yes |
| Connection Error | - | Yes |
| Timeout | - | Yes |
What Does NOT Trigger Fallback
Client errors indicate problems with your request that won’t be fixed by trying another model:| Error | Code | Triggers Fallback |
|---|---|---|
| Bad Request | 400 | No |
| Authentication Error | 401 | No |
| Permission Denied | 403 | No |
| Not Found | 404 | No |
| Validation Error | 422 | No |