Basic example
How it works
When the primary provider fails, the gateway automatically tries the next provider:Three-provider setup
Add multiple providers for maximum reliability:Provider order
Providers are tried in alphabetical order, not the order they are configured, to control order use themodel_selection.strategy to specify the order:
Combining multi-key and multi-provider
Maximum resilience with multiple keys per provider and explicit ordering:model_selection.strategy ensures providers are tried in the specified order, not alphabetically. The only_allow_configured_providers option restricts requests to only the configured providers.
Performance-based selection
Use model selection strategies to prefer providers based on metrics:Regional failover
For providers that offer regional availability, you can use the custom providers feature to add specific regions:Cost optimization
Prefer cheaper providers with fallback to premium:Real-world production example
Enterprise setup with multiple providers:- 6 total provider API keys across 3 providers
- Automatic failover at both key and provider levels
- Performance-based selection
- Up to 3 minutes of retry attempts
Client configuration
For cross-provider failover, clients must specify multiple models:Best practices
- Configure at least 2 providers for reliability
- Order providers by preference (fastest/cheapest first)
- Use multiple keys per provider for key-level failover
- Monitor provider metrics to optimize order
- Test failover regularly to ensure it works
- Set appropriate timeouts to fail fast
See also
- Multi-Key Failover - Multiple keys per provider
- Error Handling - Understanding retry logic
- Configuring Providers - Provider setup