Skip to main content
HTTP 522 Connection Timed Out
Cloudflare-specific: the TCP connection to the origin server timed out.
5xx · Server error✓ retryable with backoff
In AI APIs specifically
Indicates the provider's origin is unreachable from Cloudflare's edge — a genuine provider-side outage signal.
Fix checklist
- Retry with generous backoff.
- Check the provider status page — 522s usually correlate with incidents.
- Fail over to an alternate provider if available.
Retry handler (TypeScript)
async function fetchWithRetry(url: string, init: RequestInit, maxRetries = 5) {
for (let attempt = 0; ; attempt++) {
const res = await fetch(url, init);
// 522 is retryable — back off and try again.
if (res.status !== 522 || 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: official documentation
Related status codes
500 Internal Server Error
The server hit an unexpected condition.
501 Not ImplementedThe 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.