Configure Helicone to automatically retry failed LLM requests, overcoming rate limits and server issues using intelligent exponential backoff.
Retrying requests is a common best practice when dealing with overloaded servers or hitting rate limits. These issues typically manifest as HTTP status codes like 429 (Too Many Requests), 500 (Internal Server Error), or 503 (Service Unavailable).
Handle rate limits gracefully - Automatically retry when you hit provider rate limits
Overcome temporary failures - Recover from transient network issues or server overload
Improve reliability - Increase the success rate of your LLM requests without manual intervention
If you’re using the AI Gateway, automatic failover is usually better than retries. However, retries are ideal when you must use a specific provider endpoint (e.g., EU-hosted models for compliance, fine-tuned models, or region-specific deployments).
To enable automatic retries, add the Helicone-Retry-Enabled: true header to your requests:
import { OpenAI } from "openai";const client = new OpenAI({ baseURL: "https://ai-gateway.helicone.ai", apiKey: process.env.HELICONE_API_KEY,});const response = await client.chat.completions.create( { model: "gpt-4o-mini", messages: [{ role: "user", content: "How do I enable retries?" }] }, { headers: { "Helicone-Retry-Enabled": "true", // Add this header and set to true } });
from openai import OpenAIimport osclient = OpenAI( base_url="https://ai-gateway.helicone.ai", api_key=os.getenv("HELICONE_API_KEY"),)response = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": "How do I enable retries?"}], extra_headers={ "Helicone-Retry-Enabled": "true", # Add this header and set to true })