Retries
The AI Gateway automatically retries failed LLM requests using exponential backoff. Retry behavior is configured server-side; observe attempts via the X-Cova-Retry-Count response header.
The AI Gateway automatically retries requests that fail with transient HTTP status codes. Retry behavior (max attempts, backoff factor, min/max delay) is configured via gateway environment variables and applies to all requests — there are no per-request retry headers.
For multi-model resilience, prefer
Fallback Chains (Cova-Fallbacks) over retries
alone. Fallbacks switch to a different provider/model on failure, while
retries re-attempt the same provider.
Retry Triggers
The gateway retries requests that fail with these status codes:
- 429 — Rate limit exceeded
- 500 — Internal server error
- 502 — Bad gateway
- 503 — Service unavailable
- 504 — Gateway timeout
- 529 — Provider overload
Client errors (4xx except 429) are not retried — they typically indicate a problem with the request itself.
How It Works
The gateway uses exponential backoff:
- Starts with a short delay (configurable via env)
- Multiplies the wait time by a backoff factor after each failed attempt
- Caps the maximum wait time (configurable via env)
- Prevents overwhelming the upstream provider while maximizing success chances
Observability: X-Cova-Retry-Count
The gateway exposes the number of retry attempts on every response via the
X-Cova-Retry-Count response header:
| Direction | Response |
| Purpose | Number of retry attempts made before the request succeeded. |
| When Set | Set when gateway-configured retries are enabled and at least one retry was attempted. Absent on first-try success or when retries are disabled. |
| Example | X-Cova-Retry-Count: 2 |
Reading the retry count
curl -i https://gateway.corevalue.dev/v1/chat/completions \
-H "Authorization: Bearer sk-cova-XXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Hi"}]}'
# Response headers include:
# X-Cova-Retry-Count: 2from openai import OpenAI
client = OpenAI(
base_url="https://gateway.corevalue.dev/v1",
api_key="sk-cova-XXXXXXXXXXXXXXXX",
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hi"}],
with_response=True,
)
# response.response.headers.get("x-cova-retry-count")import { OpenAI } from "openai";
const client = new OpenAI({
baseURL: "https://gateway.corevalue.dev/v1",
apiKey: "sk-cova-XXXXXXXXXXXXXXXX",
});
const { data, response } = await client.chat.completions
.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hi" }],
})
.withResponse();
// response.headers.get("x-cova-retry-count")Legacy Retry Request Headers
The following request headers were supported by the legacy Cloudflare Worker proxy but are not read by the current AI Gateway. Sending them has no effect. Retry behavior is now configured server-side via environment variables.
| Header | Legacy purpose | Current replacement |
|---|---|---|
Cova-Retry-Enabled | Enable per-request retries | Env-configured server-side |
Cova-Retry-Num | Max retry attempts | Env-configured |
Cova-Retry-Factor | Backoff multiplier | Env-configured |
Cova-Retry-Min-Timeout | Min retry delay | Env-configured |
Cova-Retry-Max-Timeout | Max retry delay | Env-configured |
See the Header Directory for the full list of unsupported headers.