Docs/AI SDK

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:

  1. Retries the same provider (with exponential backoff)
  2. Falls back to equivalent models on other providers
  3. Opens circuit breaker if a provider is consistently failing

Configuration

Codetext
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:

Codetext
// 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:

Codetext
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:

StateBehavior
ClosedNormal operation, requests go through
OpenProvider is failing, skip and use fallback
Half-OpenTesting if provider recovered
Codetext
// 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 TypeRetry?Fallback?
Rate limit (429)Yes (with backoff)Yes
Server error (500+)YesYes
TimeoutYesYes
Auth error (401)NoNo
Bad request (400)NoNo

Monitoring

Track failover events in the dashboard:

  • Total failovers per day
  • Fallback success rate
  • Provider reliability scores
  • Circuit breaker triggers