Overview
LiteLLM automatically retries failed requests with intelligent backoff strategies. Retries help handle transient failures like rate limits, timeouts, and temporary service disruptions.Default Retry Behavior
By default, LiteLLM retries requests 2 times (3 total attempts including the initial request).Configuring Retries
Global Retry Configuration
Set retries for all requests:Per-Request Retry Configuration
Router Retry Configuration
Retry Policies
Customize retry behavior based on error type:Basic Retry Policy
Available Error Types
Configure retries for specific error types:TimeoutErrorRetries- Connection/request timeoutsRateLimitErrorRetries- Rate limit (429) errorsInternalServerErrorRetries- Server errors (500, 502, 503, 504)BadRequestErrorRetries- Bad request (400) errorsAuthenticationErrorRetries- Authentication (401, 403) errorsContentPolicyViolationErrorRetries- Content filtering errorsUnsupportedParamsRetries- Unsupported parameter errors
Model Group Retry Policies
Set different retry policies for different model groups:Retry Timing
Retry After
Set minimum wait time before retrying:Exponential Backoff
LiteLLM uses exponential backoff automatically:Exponential backoff helps avoid overwhelming rate-limited services and increases the chance of successful retries.
Streaming with Retries
Retries work with streaming responses:Async Retries
Retries work seamlessly with async operations:Monitoring Retries
Custom Retry Logging
Response Headers
Retry information is included in response metadata:Retry vs Fallback
Understanding the Difference
Retries: Attempt the same model/deployment multiple timesFallbacks: Switch to a different model/deployment after retries failExecution Order: LiteLLM tries retries first, then fallbacks
Combined Retry and Fallback
Best Practices
-
Set appropriate retry counts
- More retries for critical requests
- Fewer retries for latency-sensitive applications
-
Configure by error type
- Retry timeouts and rate limits aggressively
- Don’t retry authentication or validation errors
-
Use exponential backoff
- Already built-in, respects API rate limits
-
Monitor retry rates
- High retry rates indicate underlying issues
- Track which models/deployments need retries
-
Combine with fallbacks
- Use retries for transient failures
- Use fallbacks for persistent failures
-
Set timeouts
- Prevent retries from taking too long
Common Retry Scenarios
Rate Limit Handling
Timeout Handling
Production Configuration
Disabling Retries
Error Handling
Related Features
- Fallbacks - Switch to different models after retries
- Load Balancing - Distribute across multiple deployments
- Cost Tracking - Monitor costs of retries
- Logging - Track retry attempts