AI
Failover
Last updated March 3, 2026
Automatic retries, provider fallback, and circuit breaker for reliable AI requests.
Cencori provides automatic failover to keep your AI applications reliable, even when providers have outages.
How It Works
When a request fails, Cencori automatically:
- Retries the same provider (with exponential backoff)
- Falls back to equivalent models on other providers
- Opens circuit breaker if a provider is consistently failing
Configuration
const cencori = new Cencori({
apiKey: 'csk_...',
failover: {
enabled: true,
maxRetries: 3,
fallbackModels: {
'gpt-4o': ['claude-3-opus-latest', 'gemini-1.5-pro'],
'claude-3-opus-latest': ['gpt-4o', 'gemini-1.5-pro'],
}
}
});Automatic Fallback
When configured, a failed request to one provider automatically falls back:
// If gpt-4o fails, automatically tries claude-3-opus-latest
const response = await cencori.ai.chat({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }],
failover: true
});
// Response includes which model was actually used
console.log(response.model); // 'gpt-4o' or 'claude-3-opus-latest'Manual Fallback Chain
Specify explicit fallback order:
const response = await cencori.ai.chat({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }],
fallbackModels: ['claude-3-opus-latest', 'gemini-1.5-pro', 'grok-2']
});Circuit Breaker
The circuit breaker prevents cascading failures:
| State | Behavior |
|---|---|
| Closed | Normal operation, requests go through |
| Open | Provider is failing, skip and use fallback |
| Half-Open | Testing if provider recovered |
// Circuit breaker settings
const cencori = new Cencori({
apiKey: 'csk_...',
circuitBreaker: {
failureThreshold: 5, // Open after 5 failures
resetTimeout: 30000, // Try again after 30s
}
});Retry Behavior
| Error Type | Retry? | Fallback? |
|---|---|---|
| Rate limit (429) | Yes (with backoff) | Yes |
| Server error (500+) | Yes | Yes |
| Timeout | Yes | Yes |
| Auth error (401) | No | No |
| Bad request (400) | No | No |
Monitoring
Track failover events in the dashboard:
- Total failovers per day
- Fallback success rate
- Provider reliability scores
- Circuit breaker triggers