Retries & Error Handling

Retries & Error Handling

Overview

Who is this for? Developers building production AI applications who need robust error handling and automatic recovery from provider failures, rate limits, and network issues.

What you'll achieve: Implement resilient AI applications with intelligent retry strategies, provider fallbacks, and comprehensive error handling that automatically recovers from transient failures.

The AI Proxy includes sophisticated retry mechanisms with provider-specific error handling, intelligent backoff strategies, and automatic failover to ensure maximum reliability.

Retry Configuration

Basic Retry Setup

<CODE_PLACEHOLDER>

Retry Configuration Parameters

ParameterDescriptionDefaultRange
max_attemptsMaximum number of retry attempts31-10
base_delay_msInitial delay between retries1000100-60000
max_delay_msMaximum delay between retries300001000-300000
exponential_baseMultiplier for exponential backoff21.1-10
jitterAdd randomization to delaytruetrue/false
retry_onSpecific error types to retry["rate_limit", "timeout", "server_error"]Array

Provider-Specific Error Handling

Rate Limit Handling

The AI Proxy automatically detects and handles provider-specific rate limits:

OpenAI & Compatible Providers

<CODE_PLACEHOLDER>

Anthropic Claude

<CODE_PLACEHOLDER>

Google AI (Gemini)

<CODE_PLACEHOLDER>

Automatic Rate Limit Detection

<CODE_PLACEHOLDER>

Advanced Retry Strategies

Exponential Backoff with Jitter

<CODE_PLACEHOLDER>

Provider Fallback Chain

<CODE_PLACEHOLDER>

Custom Retry Conditions

<CODE_PLACEHOLDER>

Error Types and Handling

Retriable Errors (Default Behavior)

Error TypeDescriptionProvider Examples
rate_limitToo many requestsAll providers
timeoutRequest timeoutNetwork/provider issues
server_error5xx HTTP statusProvider downtime
model_overloadedModel capacity exceededHigh demand periods
insufficient_quotaAccount limits reachedUsage-based providers

Non-Retriable Errors (Fail Fast)

Error TypeDescriptionAction
invalid_requestMalformed requestFix request format
authentication_errorInvalid API keyCheck credentials
content_policy_violationContent blockedModify content
model_not_foundInvalid model nameUse valid model
context_length_exceededInput too longReduce input size

Implementation Examples

Node.js with Custom Error Handling

<CODE_PLACEHOLDER>

Python with Async Retries

<CODE_PLACEHOLDER>

React Hook with Error Recovery

<CODE_PLACEHOLDER>

Monitoring and Debugging

Retry Metrics

<CODE_PLACEHOLDER>

Response Headers:
<CODE_PLACEHOLDER>

Error Response Format

<CODE_PLACEHOLDER>

Best Practices

Production Configuration

<CODE_PLACEHOLDER>

Circuit Breaker Pattern

<CODE_PLACEHOLDER>

Graceful Degradation

<CODE_PLACEHOLDER>

Troubleshooting

Common Retry Issues

Infinite Retry Loops
<CODE_PLACEHOLDER>

Insufficient Rate Limit Handling
<CODE_PLACEHOLDER>

Memory Leaks in Long Retry Chains
<CODE_PLACEHOLDER>

Next Steps