Skip to main content

Overview

LiteLLM provides robust fallback mechanisms to ensure high availability of your LLM applications. When a model fails or is unavailable, LiteLLM automatically retries with fallback models or deployments.

How Fallbacks Work

Fallbacks execute in order when:
  • API returns an error (rate limit, timeout, service unavailable)
  • Model deployment is down
  • Context window is exceeded
  • Content policy violations occur

Basic Fallback Configuration

Single Model Fallback

Router Fallbacks

The Router provides advanced fallback logic across multiple deployments:

Fallback Types

1. Default Fallbacks

Apply to all models globally:

2. Model-Specific Fallbacks

Define fallbacks per model:

3. Context Window Fallbacks

Automatic fallback when context window is exceeded:

4. Content Policy Fallbacks

Fallback when content policy violations occur:

Advanced Fallback Configuration

Fallback with Custom Parameters

Pass different parameters to fallback models:

Controlling Fallback Behavior

Fallback Policies

Allowed Fails Policy

Control when a deployment enters cooldown:

Deployment Cooldown

When a deployment fails multiple times, it enters a cooldown period:
During cooldown, the deployment is excluded from routing but can still be used as a last resort if all others fail.

Async Fallback Support

Fallbacks work with async operations:

Monitoring Fallbacks

Tracking Fallback Usage

Response Headers

Fallback information is included in response headers:

Best Practices

Fallback Strategy Recommendations

  1. Order by capability - Place most capable/expensive models first
  2. Consider cost - Fallback to cheaper alternatives when appropriate
  3. Mix providers - Diversify across OpenAI, Anthropic, Google, etc.
  4. Test thoroughly - Verify fallbacks work as expected
  5. Monitor cooldowns - Alert when deployments enter cooldown
  6. Set reasonable limits - Balance availability vs. cost

Common Patterns

High Availability Pattern

Cost-Optimized Pattern

Error Handling