Cloudflare 524 Timeout on LLM APIs: The 100s Limit and How to Fix It

Blog / Edge & CDN

Cloudflare 524 Timeout on LLM APIs: The 100s Limit and How to Fix It

If an LLM API call returns 524 timeout, it means a Cloudflare node on the request path had already connected to the origin but received no HTTP response within roughly 100 seconds, so Cloudflare ended the request. The model itself most likely did not fail; it may still be generating. There are only two ways out: make the origin start sending data earlier, or stop making one HTTP request wait that long.

Who actually returns the 524?

524 is a Cloudflare-specific status code, not part of the HTTP standard, so you only see it on requests that pass through a Cloudflare proxy. The official documentation describes it as: the TCP connection between Cloudflare and the origin was established, but the origin did not respond within the timeout (see Cloudflare's Error 524 page). The default wait is 100 seconds. Enterprise plans can adjust it within limits; check the official docs for specifics.

The catch is that an LLM request may cross more than one Cloudflare layer:

  • your own app or relay service sits behind Cloudflare;
  • the third-party gateway or relay you call sits behind Cloudflare;
  • some model providers' API endpoints are themselves behind Cloudflare.

The fix depends entirely on which layer returned the 524. If it is your own site, change your configuration. If it is upstream, you can only change how you call it or contact the operator.

Check headers and timing with curl

The most direct check is to look at the response headers and total elapsed time:

curl -sS -o /tmp/body.txt -D - \
  -w '\nHTTP %{http_code}  total %{time_total}s  ttfb %{time_starttransfer}s\n' \
  https://your-api-host/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d @request.json

What to look for:

ObservationWhat it tells you
server: cloudflareThe response came from a Cloudflare edge
cf-ray: xxxxxxxx-NRTPresent on every request through Cloudflare. The last three letters are the code of the data center that handled it. Give the full Ray ID to the other party when reporting a problem
Status 524, total close to 100 secondsA classic origin read timeout
Response body is an HTML error page, not JSONThe error came from Cloudflare, not a business error from the model service
Status 504 after about 60 secondsMore likely the default read timeout of a reverse proxy such as Nginx, not Cloudflare

If your domain is on Cloudflare, search the dashboard logs by Ray ID to confirm whether the timeout is on your own layer. If the Cloudflare information in the headers belongs to an upstream domain, the timeout is in the upstream layer.

For what each error code means and whether to retry, see the LLM API error code cheat sheet.

Rule out an edge outage first

A 524 can also mean not that your request is slow but that a Cloudflare region is having problems. cdnping syncs Cloudflare's official status page every 15 minutes. According to the records cdnping synced, between 2026-09-17 and 2026-10-17 the Cloudflare status page listed 3 incidents marked major and 19 marked minor. Several of them involved 5xx errors or the network:

  • 2026-10-16 13:46 (UTC), "Increased HTTP 5xx Errors Ashburn", minor;
  • 2026-10-15 10:47 (UTC), "Increased HTTP 502 Errors", minor, lasting about 591 minutes;
  • 2026-10-10 04:13 (UTC), "Elevated Errors in China Network Colos", minor.

These did not necessarily show up as 524, but they show that the edge layer itself can produce 5xx errors. When you see 5xx errors across the board, open the API status page to see probe results for each provider's endpoints along with synced official incidents, then check Is it down? for reports from other users, and only then touch your code. For how to read incident severity on official status pages, see How to read the OpenAI and Claude status pages.

Why are LLM requests so prone to 524?

An ordinary web API returns in a few hundred milliseconds, so 100 seconds is a generous ceiling. LLM requests are different: a non-streaming call does not return its first byte until the whole output has been generated, and that time depends on several things:

  1. Output length. Total time is roughly time to first token plus output tokens divided by generation speed. A long article or code listing of several thousand tokens can easily exceed 100 seconds without streaming. For estimating speed and total time, see How to read model output speed in tokens/s.
  2. The thinking phase of reasoning models. Thinking tokens may not be returned to you, but they take time to generate and are billed. The visible output can be short while the real elapsed time is long; see How reasoning tokens are billed.
  3. Large context. With hundreds of thousands of input tokens, the prefill stage alone takes time, and time to first token grows noticeably.
  4. Upstream queueing. At peak times or when capacity is tight, time spent queued upstream also counts toward the 100 seconds.

So it is common for the same endpoint to handle short questions without error and then return 524 on long tasks. That does not necessarily indicate a network problem.

Fix 1: switch to streaming

This is the smallest change. With stream: true, the origin starts returning response headers and data when the first token is generated. Cloudflare gets its response, and the 100-second origin timeout does not fire at the start.

Two things to watch.

First, a streaming response can also drop midway. Once data is flowing, if the gap between two chunks is too long, a proxy may still treat the connection as idle and close it. A reasoning model may produce no visible output for a long time while thinking. In that case check whether the API sends heartbeat events (for example, Anthropic's streaming API sends ping events), or have your own middle layer periodically write an SSE comment line (a line starting with a colon) to keep the connection alive. The heartbeat interval should be well below the shortest idle timeout on the path. For the same problem with WebSockets, see WebSocket connections drop after about 100 seconds through Cloudflare.

Second, no layer in between may buffer. If there is an Nginx behind Cloudflare with proxy_buffering on, streamed data is accumulated and sent all at once, which is the same as not streaming, and you still get a 524. At minimum, check these Nginx settings:

location /v1/ {
    proxy_pass http://upstream_llm;
    proxy_http_version 1.1;
    proxy_buffering off;
    proxy_cache off;
    proxy_read_timeout 600s;   # max wait between two reads, not a cap on the whole request
    proxy_send_timeout 600s;
}

Your application can also add the X-Accel-Buffering: no header to the SSE response. For a full walkthrough of buffering problems, see SSE streaming gets buffered and arrives all at once; for streams that cut off midway, see LLM streaming output disconnects midway.

Fix 2: use an async job with polling

Some scenarios do not suit streaming: batch processing, background report generation, or a caller that is a legacy system without streaming support. Then turn "one long request" into "one fast request plus a few status checks":

  1. The client sends POST /jobs; the server puts the task in a queue and immediately returns 202 and a job_id, in milliseconds;
  2. A background worker calls the model, over a connection that does not pass through Cloudflare or uses a channel not subject to the 100-second limit;
  3. The client polls GET /jobs/{job_id} every few seconds and fetches the result when done; you can also use a callback notification instead.
# Sketch: submit, then poll with an overall time limit
import time, requests

job = requests.post(f"{BASE}/jobs", json=payload, timeout=10).json()
deadline = time.time() + 900
while time.time() < deadline:
    r = requests.get(f"{BASE}/jobs/{job['job_id']}", timeout=10).json()
    if r["status"] in ("succeeded", "failed"):
        break
    time.sleep(3)

This way every HTTP request through Cloudflare is short, and the 100-second limit stops being relevant. Some model providers also offer a background mode or batch API built on the same idea; whether it is available and how it is billed is up to each provider's official documentation.

The async approach adds a state store and a worker, so it is more complex, but it has an extra benefit: results land in your own storage, so a network blip on the client does not lose content you already paid to generate.

Fix 3: align timeouts across every layer

Whether you choose streaming or async, list the timeout at every layer on the path and check them. The principle: the layer closest to the model should time out first and the layer closest to the user last, so that when something fails you get an error your own code can recognize (such as a JSON upstream-timeout error) rather than an anonymous Cloudflare error page.

Timeout checklist

LayerCommon default or limitWhat to check
Client SDK / HTTP libraryVaries by SDK; see its docsSet timeout explicitly; for non-streaming long tasks make it longer than the expected generation time
Cloudflare proxyWaits about 100 seconds for the origin responseSwitch long requests to streaming or async; adjustable on Enterprise, see official docs
Nginx reverse proxyproxy_read_timeout defaults to 60 secondsRaise it and turn off buffering for streaming; it is the gap between two reads
Application server (e.g. gunicorn, uvicorn)Worker timeouts varySync workers handling long requests get killed; watch the logs for worker timeout
The client your service uses to call the modelVaries by SDKSet it slightly shorter than the outer layers and return a clear error code to the caller on timeout
Model serviceSet by the providerWatch time to first token and output speed to estimate the longest possible duration

A common trap: the outer Nginx is set to 60 seconds and Cloudflare to 100, so users see Nginx's 504 first and keep looking for the cause in Cloudflare. Fill this table in for your own path and you can usually see which layer cuts first.

Adjust retries too

Be careful with automatic retries after a 524. For a non-streaming long task, retrying as is will most likely be cut at 100 seconds again, just duplicating the cost. A sensible approach: do not immediately retry the same request on a 524; fall back to the streaming or async path instead. When you do need to retry, use exponential backoff with a retry budget. For how to write it, see How to write LLM API retries.

Are you still billed after the disconnect?

This is the cost of a 524 that people most often overlook. Cloudflare closes only its leg between it and you; the origin and the model side may not know the request was abandoned. Many servers do not stop generating right after the client disconnects, and tokens already generated, even the complete output, may still appear on the bill. Behavior differs by provider; rely on the provider's documentation and your actual bill.

Suggested check:

  1. Record the time and request ID of every 524;
  2. Find the matching records in the provider's usage details by time and see whether any output tokens were billed;
  3. If so, each 524 plus one retry means paying twice for the same task.

For how to audit a bill, see How token billing works. From a cost standpoint this is also a reason to prefer streaming or async: at least you get the generated content.

If you deploy an AI app behind Cloudflare

If the 524 comes from your own site, work through it in this order:

  1. Use the curl command above to confirm the 524 comes from your own zone, and note the Ray ID;
  2. Find endpoints that take more than 100 seconds and convert them to streaming first;
  3. Split endpoints that cannot stream into async jobs;
  4. Check the timeout and buffering settings of Nginx and the application server, and line them up from the inside out using the checklist;
  5. Set up separate alerts for 524 and upstream timeouts instead of mixing them with ordinary 5xx errors.

For other configuration of AI apps on Cloudflare, such as which paths should not be cached and how to do rate limiting and origin protection, see Speeding up AI apps with Cloudflare. cdnping's own edge acceleration service is described at cdnping Edge. To first check your connection and round-trip latency to each model API, run a speed test on the cdnping homepage; the probe methodology is described in Methodology.

Related articles

Keep reading