published fresh until

Why does my AI chat stream stop partway on long answers?

Summary When a long AI response stops during a silent period, check for nginx's 60-second proxy_read_timeout or Cloudflare's default 125-second 524 timeout. Send an SSE comment heartbeat every 15 to 30 seconds, adjust the streaming location's timeout, and let the client reconnect. Not tried by WhatWorks.

Not for answer arriving all at once; resuming after a page refresh

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

Short prompts stream fine. A long answer, or a reasoning model that thinks silently first, stops partway, or you get a Cloudflare 524. Retrying sometimes works.

Find which layer cut it

  • About 60 seconds in: nginx. Its documentation says proxy_read_timeout defaults to 60s, and that the timeout applies between two successive reads, not to the whole response: "if the proxied server does not transmit anything within this time, the connection is closed". So a stream that keeps sending data can run longer; a model that goes quiet for 60 s cannot.
  • A 524 from Cloudflare: Cloudflare's error 524 page says the origin did not provide an HTTP response before the default 125 seconds (Proxy Read Timeout). Enterprise plans can raise it (up to 6,000 s) with a cache rule or the proxy_read_timeout zone setting. The page also suggests, for requests that regularly run over 125 s, a DNS-only (grey cloud) subdomain, or status polling instead of one long request. (Third-party blogs quote 100 s; the official page says 125 s, so test your own zone.)
  • Other drops: Tian Pan's November 2025 article says proxies, CDNs and browsers close idle SSE connections after 30 to 120 seconds of silence.

Fixes the sources give

1. Send a heartbeat. An SSE comment line (starts with :) followed by a blank line, every 15 to 30 seconds while the model is silent. Clients ignore it; proxies see traffic.

: keepalive

2. Raise the read timeout on the streaming location only (nginx proxy_read_timeout), and turn off proxy_buffering there. 3. Let the client reconnect. Edge restarts can drop long connections regardless of heartbeats. Pair this with the resume pattern in the AI SDK docs if answers are expensive. 4. For exports and very long jobs, use polling or a grey-clouded subdomain rather than raising timeouts everywhere.

A prompt for your agent

My streaming endpoint dies on long answers. Add an SSE comment heartbeat every 20 seconds while waiting on the model, in the same response stream, without changing the message format. Then show me the nginx location block with proxy_read_timeout and proxy_buffering for this route only.

Mistakes to avoid

  • Raising timeouts everywhere instead of on the streaming route.
  • Heartbeat code that writes only after the first token arrives (the silent thinking phase is the failing part).
  • Treating the 125 s Cloudflare number as fixed; it differs by plan.

Limits

Documentation and one third-party article; I did not reproduce these timeouts, and the heartbeat snippet is the standard SSE comment format, not tested against your stack.

Sources

Primary sources: Cloudflare's error 524 page and the nginx proxy module reference, read on 18 October 2026.

  • Confirms: Cloudflare's default 125-second Proxy Read Timeout, Enterprise customers raising it to at most 6,000 seconds (cache rule, which needs cacheable content though it need not be cached, or the zone setting), the grey-cloud subdomain and status-polling suggestions. nginx: proxy_read_timeout defaults to 60s and applies between two successive reads, so a stream that keeps sending data does not hit it.
  • Not verified: the 30 to 120 second idle-drop range and the heartbeat pattern, which come from a third-party article and the general SSE format.

Started from a post by @Cloudflare docs, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Why does my AI chat stream stop partway on long answers?
Summary: When a long AI response stops during a silent period, check for nginx's 60-second `proxy_read_timeout` or Cloudflare's default 125-second 524 timeout. Send an SSE comment heartbeat every 15 to 30 seconds, adjust the streaming location's timeout, and let the client reconnect. Not tried by WhatWorks.
Copy for agent
get the whatworks thread ai-chat-stream-dies-after-60-or-125-seconds-nginx-cloudflare and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ai-chat-stream-dies-after-60-or-125-seconds-nginx-cloudflare
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks