Skip to main content

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 timeouts
  • RateLimitErrorRetries - Rate limit (429) errors
  • InternalServerErrorRetries - Server errors (500, 502, 503, 504)
  • BadRequestErrorRetries - Bad request (400) errors
  • AuthenticationErrorRetries - Authentication (401, 403) errors
  • ContentPolicyViolationErrorRetries - Content filtering errors
  • UnsupportedParamsRetries - 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

  1. Set appropriate retry counts
    • More retries for critical requests
    • Fewer retries for latency-sensitive applications
  2. Configure by error type
    • Retry timeouts and rate limits aggressively
    • Don’t retry authentication or validation errors
  3. Use exponential backoff
    • Already built-in, respects API rate limits
  4. Monitor retry rates
    • High retry rates indicate underlying issues
    • Track which models/deployments need retries
  5. Combine with fallbacks
    • Use retries for transient failures
    • Use fallbacks for persistent failures
  6. Set timeouts
    • Prevent retries from taking too long

Common Retry Scenarios

Rate Limit Handling

Timeout Handling

Production Configuration

Disabling Retries

Error Handling