How It Works
The fallback chain is an ordered list of providers. Each request traverses the list until it succeeds or all options are exhausted:Configuration
- Environment Variables
- Server Flags
- Helm Chart
Error Classification
The system automatically classifies each failure to decide the strategy:Exponential Cooldown
After consecutive failures, the provider enters cooldown with exponential backoff:In interactive CLI mode, authentication errors (401) automatically trigger an OAuth token refresh and retry the request. In server mode (fallback chain), authentication errors receive immediate maximum cooldown (5m). A successful request clears all cooldown for the provider. Use
ResetCooldowns() to clear manually (e.g., after updating credentials).Health Monitoring
The chain tracks the state of each provider in real time:Tool Use with Fallback
The fallback chain also supportsSendPromptWithTools for providers that implement the ToolAwareClient interface. Providers without native tool use support are automatically skipped in the tool call chain.
Best Practices
Order by cost-effectiveness
Place the cheapest/fastest provider first in the chain.
Diversify providers
Mix providers from different companies for real resilience.
Configure models per provider
Use models with equivalent capabilities to maintain quality.
Monitor health
Regularly check if any provider is in persistent cooldown.
Chain entries are identified by provider name â each provider can appear only once, and all entries of the same name share one key, endpoint and health state. To add a third-party OpenAI-compatible gateway as an entry separate from OpenAI, use the OpenRouter preset pointed at it: set
OPENROUTER_API_KEY to the gateway key and OPENROUTER_API_URL to the gatewayâs full chat completions URL, then list OPENROUTER alongside OPENAI in the chain.