Skip to main content
HTTP 500 Internal Server Error
The server hit an unexpected condition. The fault is on the provider's side.
5xx · Server error✓ retryable with backoff
In AI APIs specifically
All providers occasionally 500 under load or on edge-case inputs. Anthropic returns api_error; OpenAI returns server_error. A reproducible 500 on a specific prompt is worth reporting.
Fix checklist
- Retry with exponential backoff and jitter (start ~1s, cap ~60s).
- Check the provider status page if 500s persist.
- Log the request ID from response headers for support tickets.
Retry handler (TypeScript)
async function fetchWithRetry(url: string, init: RequestInit, maxRetries = 5) {
for (let attempt = 0; ; attempt++) {
const res = await fetch(url, init);
// 500 is retryable — back off and try again.
if (res.status !== 500 || attempt >= maxRetries) return res;
const retryAfter = Number(res.headers.get("retry-after"));
const delay = Number.isFinite(retryAfter) && retryAfter > 0
? retryAfter * 1000
: Math.min(60_000, 1000 * 2 ** attempt) * (0.5 + Math.random()); // expo backoff + jitter
await new Promise((r) => setTimeout(r, delay));
}
}Spec: RFC reference
Related status codes
501 Not Implemented
The server does not support the functionality required to fulfil the request..
502 Bad GatewayA gateway or proxy received an invalid response from the upstream server..
503 Service UnavailableThe server is temporarily unable to handle the request — overload or maintenance.
504 Gateway TimeoutA gateway did not receive a timely response from the upstream server..