How to Fix Cloudflare Error 524 on Long LLM Requests (Without an Enterprise Plan)
The 100-second limit is about the first byte, not the whole response. That single fact is the fix, and it costs nothing.
On this page
- The fix order at a glance
- 1. Work out who actually cut the request
- 2. Stream, and the problem disappears
- 3. If you can't stream, at least flush early
- 4. The answer for anything genuinely long
- 5. Raising the limit, and why it probably isn't available
- 6. What I'd do first, in order
- Match your symptom to the fix
- When streaming didn't fix it
A long generation works perfectly on localhost. Put it behind Cloudflare and it dies, always at the same moment:
Error 524: A timeout occurred
You raise proxy_read_timeout in nginx. Nothing changes. You raise it again, to something absurd like 600 seconds, and it still fails at the same place. The request is being cut somewhere you don't control, and no amount of configuration on your own server reaches it.
#The fix order at a glance
| # | Fix | Time | Works on a Free plan? |
|---|---|---|---|
| 1 | Confirm it's Cloudflare cutting it, not you | 5 min | — |
| 2 | Stream the response | 1 hour | Yes |
| 3 | Flush headers early | 20 min | Yes |
| 4 | Background job plus polling | Half a day | Yes |
| 5 | Raise the proxy read timeout | 10 min | No, Enterprise only |
#1. Work out who actually cut the request
Before changing anything, find out whose timeout you're hitting, because the fix is completely different depending on the answer. Time the failure with a stopwatch or a log line — the number tells you almost everything, and it's a far faster diagnosis than reading configuration files.
It fails at almost exactly 100 seconds. That's Cloudflare. The limit is fixed on Free, Pro and Business, and nothing you set on your origin will move it.
It fails at a round number well below 100 — 30, 60 or 90 seconds. Cloudflare didn't cut this one. Your own stack did, and the usual suspects are nginx's proxy_read_timeout, a PHP or FastCGI limit, a load balancer in front of the app, or the HTTP client's own timeout. Fix it where it actually is.
The quickest confirmation is to bypass the proxy entirely. Call the origin directly by IP, or on the grey cloud DNS setting with proxying switched off, and see whether the same request completes. If it does, you've proved which side is cutting it.
#2. Stream, and the problem disappears
This is the fix worth building, and it's worth understanding why it works rather than treating it as a trick. The 100 seconds is a time-to-first-byte budget, not a total-duration budget. Cloudflare is waiting for your origin to say something — anything. Once bytes are flowing it will happily carry a response that takes 10 minutes.
Which means a streaming LLM response, where the first token typically arrives in under 2 seconds, never comes close to the limit no matter how long the full generation runs:
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
app = FastAPI()
@app.post("/generate")
def generate(prompt: str):
def tokens():
with client.messages.stream(
model="claude-sonnet-4-5",
max_tokens=4096,
messages=[{"role": "user", "content": prompt}],
) as stream:
for text in stream.text_stream:
yield text
return StreamingResponse(tokens(), media_type="text/plain")
You get a second benefit for free, and it's arguably the bigger one: users see output immediately instead of staring at a spinner for a minute, which changes how fast the product feels far more than any actual speed-up would.
#3. If you can't stream, at least flush early
Some responses genuinely can't be streamed — you need the whole structured result before you can validate or transform it. You can still beat the timer by sending something early, because the budget only cares that bytes arrive, not that they're useful.
Send the headers and a small padding chunk as soon as the request arrives, keep the connection alive with a periodic byte while the real work happens, and then write the body when it's ready. For Server-Sent Events a comment line works as a heartbeat and clients ignore it:
: keepalive
This is more fragile than real streaming and I'd treat it as a stepping stone rather than a destination. Intermediate proxies and client libraries buffer in ways that are hard to predict, and a fix that depends on nobody buffering is a fix that breaks quietly.
#4. The answer for anything genuinely long
Once a task reliably runs past a minute, holding an HTTP connection open for it is the wrong shape regardless of Cloudflare. Accept the request, return a job id immediately, do the work in a queue worker, and let the client poll or subscribe for the result. Every request then finishes in milliseconds and no timeout anywhere in the chain is relevant.
It's more work than streaming and it's the right call for batch generation, long document processing, or anything a user starts and walks away from. The automation tools in the workflow shortlist do this pattern for you if you'd rather not build the queue yourself.
#5. Raising the limit, and why it probably isn't available
Cloudflare's proxy read timeout can be raised above 100 seconds — up to 6000 — through a Cache Rule or the zone settings API. That's an Enterprise feature. If you're on Free, Pro or Business, the setting isn't there to change, and advice telling you to adjust it through Page Rules on a lower plan is out of date or simply wrong. Check Cloudflare's current documentation rather than a blog post if this matters to your decision, including this one.
#6. What I'd do first, in order
Time the failure. Note the number. If it's 100, stream. If it's 60, it's yours.
That's the whole triage, and it takes 5 minutes. I've watched people spend a day editing nginx configuration for a limit nginx never set, because nobody timed the failure before they started changing things. The number is free and it points straight at the layer.
#Match your symptom to the fix
| What you're seeing | Likely cause | Go to |
|---|---|---|
| Fails at almost exactly 100 seconds | Cloudflare's fixed limit | 2 |
| Fails at 30, 60 or 90 seconds | Your own proxy or app | 1 |
| Works with proxying off | Confirmed Cloudflare | 2 |
| Fails only on long prompts | Generation time crossing the limit | 2 |
| Streaming added, still 524 | Something downstream is buffering | 3 |
#When streaming didn't fix it
If you've added streaming and still see 524s, something between your application and Cloudflare is buffering the response until it's complete, which defeats the entire point. nginx is the usual culprit, and the fix is to turn buffering off for that location:
location /generate {
proxy_pass http://127.0.0.1:8000;
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding on;
}
Verify it with curl -N against your origin directly, which disables curl's own buffering and shows you tokens as they arrive. If they appear gradually there and all at once through the proxy, you've found your buffer. Check any application-level compression middleware too — gzip that collects the whole body before compressing it will hold your stream exactly as effectively as nginx will.
Frequently asked questions
Does the 100 seconds cover the whole response?
No, and this is the detail that matters. It's a limit on how long Cloudflare waits for the first bytes from your origin. Once a response has started, a long one is fine, which is exactly why streaming works.
Can I raise the limit on a Pro or Business plan?
No. The proxy read timeout is fixed at 100 seconds on Free, Pro and Business. Raising it is an Enterprise feature, configured through a Cache Rule or the zone settings API.
Is 524 different from 504?
Yes. 524 is Cloudflare's own code for an origin that didn't respond in time. A 504 is a standard gateway timeout and usually comes from your own proxy, so it points at a different layer.
Will WebSockets avoid this?
They sidestep the first-byte timer, since the connection is established quickly and then stays open. It's a much bigger change than streaming over HTTP, so try streaming first.
Written by
Vemuri Abhiram
Founder & Editor
Vemuri Abhiram is the founder and editor of Underread, where he writes about AI tools, software, and practical technology. He covers hands-on tool reviews, detailed guides, product comparisons, and emerging technologies.
You might also like
How to Fix “CUDA out of memory” When Running a Local LLM
Why a model that loaded yesterday runs out of VRAM today, and the 5 fixes in the order that costs you the least quality.
Vemuri Abhiram6 min read
How to Fix “The requested webhook is not registered” in n8n (404)
Why an n8n webhook works while you watch it and 404s afterwards, and the 5 causes ranked by how often they're the answer.
Vemuri Abhiram5 min read
How to Fix “operator does not exist: vector <=> vector” in Supabase and pgvector
Why a pgvector similarity search fails with error 42883 inside a Supabase function, and the fix with the fewest side effects.
Vemuri Abhiram5 min read
More from Underread, once a week.
The guides worth reading and the tests worth trusting. One email, every Friday.
No spam. Unsubscribe in one click.

