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
CHATCLI_FALLBACK_PROVIDERS (or --fallback-providers) is the only switch; the server reads no separate enable variable, and neither the Helm chart nor the operator writes one. A provider without CHATCLI_FALLBACK_MODEL_<PROVIDER> runs its own default model (its model variable, such as OPENAI_MODEL, then the built-in default); only the primary provider keeps the server model. maxRetries: 0 (or CHATCLI_FALLBACK_MAX_RETRIES=0) fails over to the next provider without retrying.
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). On the server the chain serves every request that names no provider or model and forwards no credential (SendPrompt, StreamPrompt, InteractiveSession, AnalyzeIssue, AgenticStep); a streamed request fails over only until the first chunk, never after text was shown, and the reply names the provider and model that answered.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.