Skip to main content

HTTP 524 A Timeout Occurred

Cloudflare-specific: the origin accepted the connection but did not reply within Cloudflare's (typically 100s) proxy timeout.

5xx · Server error✓ retryable with backoff

In AI APIs specifically

The classic long-stream killer: a non-streaming request to a slow model exceeds Cloudflare's 100-second window even though the model is still working. Streaming keeps bytes moving and resets the clock — switch any request that can take >90s to streaming.

Fix checklist

  • Use streaming for any generation that can exceed ~90 seconds.
  • Lower max_tokens on non-streaming calls.
  • Split very large jobs into smaller requests or use the batch API.
  • Retry — the upstream work may have completed; use idempotency keys to avoid double-billing.

Retry handler (TypeScript)

async function fetchWithRetry(url: string, init: RequestInit, maxRetries = 5) {
  for (let attempt = 0; ; attempt++) {
    const res = await fetch(url, init);
    // 524 is retryable — back off and try again.
    if (res.status !== 524 || 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