Fix Claude Code "Streaming Response Ended" Errors

Zivv••35 min read
On this page
  1. What the Message Actually Says
  2. Causes and Fixes at a Glance
  3. Step 1: Confirm Where Requests Are Going
  4. Step 2: Test Streaming Directly with curl -N
  5. Step 3: Rule Out Local Proxies and VPNs
  6. Step 4: If You Run Your Own nginx or Gateway
  7. Step 5: Make Each Request Smaller
  8. Should You Worry About the Retry?
  9. How Zivv Handles Streaming
  10. Prevention Checklist
  11. FAQ

The full message usually looks like this, sometimes with a leading ●:

● Streaming response ended before any complete data was received. Retrying without streaming. If this keeps happening, check any proxy or gateway between Claude Code and your model provider.

This guide is for Claude Code users who point ANTHROPIC_BASE_URL at a gateway, work behind a corporate proxy or VPN, or run their own nginx in front of the API. It explains what the message means, then walks the chain one hop at a time: base URL, a raw curl test, local proxies, self-hosted reverse proxies, and request size.

What the Message Actually Says

Claude Code calls /v1/messages with streaming (server-sent events) by default. The server sends response headers, then writes events one at a time; each event is an event: line, a data: line and a blank line, and a healthy stream ends with message_stop. The SSE streaming guide covers the format in detail.

"Ended before any complete data was received" means the connection was established, possibly even with headers received, but it closed before one full event came through. That is different from a stream dying halfway through an answer: here nothing was delivered at all.

"Retrying without streaming" is Claude Code's fallback. It sends the same request again as a regular, non-streaming call. That often rescues the request, but it is not free:

  • A non-streaming call returns nothing until the whole reply is generated, so a long answer can sit silent for minutes
  • Non-streaming calls are more likely to hit a total-duration limit somewhere. On Zivv, for example, a non-streaming request waits at most 300 seconds for the upstream's response headers, which a long generation can approach
  • If the root cause stays, every request pays for a failed stream plus a retry, and the session feels sluggish

The last sentence, "check any proxy or gateway between Claude Code and your model provider", is the real hint. Claude Code itself is rarely the culprit; something in the path is.

Causes and Fixes at a Glance

What you observeMost likely causeFix
In a curl test, output arrives all at once after a long wait, or neverA layer is buffering SSE (nginx proxy_buffering, compression, CDN)Disable buffering and compression for streaming paths (step 4)
Failures cluster around the same duration, such as 60 or 100 secondsAn idle or time-to-first-byte timeout shorter than the model's thinking timeRaise that layer's read timeout, or use a gateway that sends keepalives
curl returns an HTML page or plain JSON instead of event: linesWrong base URL, or a proxy, WAF or login page intercepting the requestCheck ANTHROPIC_BASE_URL, retest without the proxy
Only happens on the office network, a VPN or an acceleratorTLS inspection or buffering in the proxy, long connections being recycledExempt the API host with NO_PROXY, compare on another network
Works fine on a phone hotspotUnstable local network, Wi-Fi handoffs, a router dropping long connectionsSwitch to a stable network first, then look at local gear
Much more frequent with long contextsLong processing before the first token gives idle timeouts more time to fire/compact the history or split the task
Happens once, then everything is fineA transient upstream or network blipNothing to do; Claude Code already retried

Step 1: Confirm Where Requests Are Going

In the same terminal you launch Claude Code from, check what is actually in effect:

echo $ANTHROPIC_BASE_URL             # for Zivv: https://zivv.pro, without /v1
env | grep -i -E "proxy|anthropic"   # look for HTTPS_PROXY, ALL_PROXY and similar
cat ~/.claude/settings.json          # the env block can also set a URL or proxy

The usual suspects:

  • ANTHROPIC_BASE_URL points at a web page or an OpenAI-compatible URL (often with a stray /v1), so the reply is not Anthropic-format SSE
  • A leftover HTTPS_PROXY or ALL_PROXY routes the request through a proxy that does not handle long-lived connections well
  • Both ~/.claude/settings.json and your shell profile set values, and the one in effect is not the one you think

If you are unsure about the setup itself, run through the Claude Code API setup guide first.

Step 2: Test Streaming Directly with curl -N

Take Claude Code out of the picture and send a streaming request straight to the gateway. -N turns off curl's own output buffering and -i prints the response headers:

curl -N -i https://zivv.pro/v1/messages \
  -H "x-api-key: $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-haiku-5-5","max_tokens":300,"stream":true,"messages":[{"role":"user","content":"Count from 1 to 30, one number per line"}]}'

A healthy run shows a content-type: text/event-stream header, then event: message_start, a series of event: content_block_delta lines appearing one by one, and finally event: message_stop. Match what you see:

curl resultMeaningNext move
Events appear line by line and end with message_stopThe gateway and this network path are fineLook at the proxy, VPN or config where Claude Code runs (step 3)
Long pause, then every event at onceSomething in the path is bufferingFind that layer and turn buffering off (step 4)
Headers arrive, then the connection closes with no eventsA layer cut the connection before the first byteNote how long it took and match it against each layer's timeouts
An HTML page or ordinary JSON comes backWrong URL, or an interception page replaced the responseFix the URL, retest without the proxy
403 this channel requires a specific clientThis key's group only accepts a specific clientThe path works; test with claude -p instead

If your key belongs to a group restricted to a specific client (such as the Claude MAX group, which is meant for Claude Code), curl will be refused. Use Claude Code's non-interactive mode as the minimal test; it answers once and exits:

claude -p "Count from 1 to 30"

To check only the key and the network, request https://zivv.pro/v1/models, which does not stream. Run every test on the machine and in the terminal where Claude Code actually runs, or the comparison means nothing.

Step 3: Rule Out Local Proxies and VPNs

If curl works from a clean environment but Claude Code keeps failing, suspect the proxy settings on that machine. Run once with the proxy variables removed:

env -u HTTPS_PROXY -u HTTP_PROXY -u ALL_PROXY \
    -u https_proxy -u http_proxy -u all_proxy \
    claude -p "Count from 1 to 30"

If that fixes it, send only the API host direct and leave everything else on the proxy:

export NO_PROXY=zivv.pro

The layers that cause this most often:

  • Corporate proxies and security gateways that inspect TLS or scan content tend to hold the response until it is complete. A stream then looks like a long silence and gets cut by a timeout. Ask IT to exempt the API host from inspection
  • VPNs and accelerators in global mode drop in-flight connections when they switch routes or reconnect. Use split routing so the API host goes direct or through one stable node
  • WSL, Docker and remote dev boxes run Claude Code in a different environment from the one where you tested curl, often with different proxy variables. Test where Claude Code really runs
  • Local networks break requests on Wi-Fi handoffs or laptop sleep; those are one-off failures and a retry is enough

Step 4: If You Run Your Own nginx or Gateway

Plenty of teams put their own reverse proxy between Claude Code and the upstream for a single egress point, extra auth or logging. With default settings that layer almost always breaks streaming: nginx enables proxy_buffering by default and proxy_read_timeout defaults to 60 seconds. At minimum, configure the streaming location like this:

location /v1/ {
    proxy_pass https://zivv.pro;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header Host zivv.pro;
    proxy_ssl_server_name on;

    proxy_buffering off;      # pass each event through as it arrives
    proxy_cache off;          # never cache streaming responses
    gzip off;                 # compression also accumulates data

    proxy_read_timeout 600s;  # max gap between two reads, not total duration
    proxy_send_timeout 600s;
}

Three things to keep in mind:

  • proxy_read_timeout limits the gap between two reads. A model can think for a long time before its first token, so the value must exceed the longest silence you expect
  • A CDN, WAF or cloud load balancer in front adds its own idle and first-byte timeouts (Cloudflare, for instance, returns a 524 when the origin does not respond within about 100 seconds). Check each one
  • After changing anything, rerun the step 2 curl against your own proxy's address; events should appear line by line

The nginx documentation is the reference for these directives. For other buffering culprits such as compression middleware and serverless platforms, see AI API streaming with SSE.

Step 5: Make Each Request Smaller

The longer the context, the longer the model works before emitting its first token, and the longer the connection sits open with no data. That silent window is exactly where idle timeouts strike. What helps:

  • Run /compact when responses slow down, and use /clear or a fresh session when you switch tasks
  • Point Claude Code at the relevant directories and files instead of having it read the whole repository
  • Break "refactor the whole project" into sub-tasks that each finish in a few minutes, and check each step before moving on

These habits also cut token spend; see Claude Code token-saving tips.

Should You Worry About the Retry?

Claude Code falls back to a non-streaming retry on its own. If the message shows up once and things carry on normally, do nothing. Step in when:

  • It keeps happening. Some layer has a persistent problem, and the fallback only makes every request wait twice. Work through the steps above
  • The non-streaming retry fails too. You will usually see a timeout or a 5xx error next, which means that layer cannot handle long requests at all. For telling timeouts and 529s apart, see 529 overloaded and timeout fixes; for gateway 502s, see 502 Bad Gateway fixes

Do not wrap Claude Code in your own retry loop. When the path is the problem, more retries just burn more time and tokens.

How Zivv Handles Streaming

If you connect through Zivv, here is what the gateway layer does, based on the code. It cannot vouch for every hop between you and Zivv, but it narrows the search:

  • No buffering on streams. Zivv's reverse proxy disables proxy_buffering and caching for API paths. Streaming responses carry Content-Type: text/event-stream, Cache-Control: no-cache and X-Accel-Buffering: no; the last header tells any nginx along the way that honors it not to buffer this response
  • A keepalive every 15 seconds. While the upstream has not started writing, or goes quiet mid-stream, Zivv writes a keepalive frame every 15 seconds (event: ping on the Anthropic protocol, a : keepalive comment line on the OpenAI-compatible one), so intermediaries do not recycle the connection as idle
  • Errors before the first token get retried or rerouted. When an upstream returns 200 and then reports an error before any content (rate limit, overload, account trouble), Zivv holds those bytes back and applies the same retry and failover rules as for an upstream that returned the error code directly. When another channel succeeds, the client never sees the failure
  • Explicit errors instead of empty streams. A failure before the first keepalive returns the real HTTP status and a JSON error body. A later failure is reported in the stream with message_start followed by an error event. If an upstream returns 200 with no data events at all, Zivv still writes an error event to end the stream rather than silently closing the connection
  • Truncated streams are not billed. When the upstream ends a stream before its terminal event, the request is recorded as failed and not charged

In the console's usage logs, each request shows its status code, duration, time to first token (TTFT) and request ID; the same ID is returned in the X-Request-ID response header. A 499 means the connection was closed from the client side first (the client, a local proxy or the network), while a 502 means the upstream did not deliver a complete response. Find the request by its timestamp and you know which side to investigate.

Prevention Checklist

  • Keep one source of configuration: environment variables or ~/.claude/settings.json, not both, and no /v1 on ANTHROPIC_BASE_URL
  • Route the API host direct (NO_PROXY) or via split routing, away from global proxies and TLS inspection
  • Before shipping a self-hosted proxy, test it with curl -N and a prompt that needs long thinking, and confirm events stream line by line without dying at a fixed duration
  • Keep sessions lean and /compact long ones regularly
  • Give each team member their own key so a failing setup shows up per key in the usage logs; see team API key and budget best practices

If you do not have a key yet, sign up for Zivv. One key works for both Claude Code and Codex, and the dashboard shows the model, status and cost of every request.

FAQ

Is this a Claude Code bug?

Usually not. The message itself says Claude Code received a stream that ended before any complete data arrived, retried without streaming, and recommends checking the proxy or gateway between it and the model provider. A single curl -N test against the gateway's streaming endpoint quickly shows whether the gateway, a proxy or the local network is at fault.

Why does it happen once and then go away?

A single occurrence is usually a transient blip: a Wi-Fi handoff, a proxy node reconnecting or a brief upstream overload can kill one stream before its first event. If the non-streaming retry succeeds, there is nothing to fix. Only repeated occurrences point to a persistent problem in some layer.

Will I be billed twice when a stream fails and Claude Code retries?

It depends on which side broke. On Zivv, a request where the upstream failed to deliver a complete response is recorded as failed and not charged. If the client side disconnected first (status 499 in the usage logs), the input the upstream already processed and any output already delivered are billed, and the non-streaming retry is a separate request billed on its own. That is a good reason to fix the root cause quickly when the message keeps appearing.

Can I just make Claude Code always use non-streaming requests?

It is not a good idea. Non-streaming calls return nothing until the full reply is generated, so long tasks can go silent for minutes, are more likely to hit total-duration limits, and cannot be watched or interrupted midway. Fixing the layer that buffers or times out, so streaming works, is the real solution.

I use Zivv. Can I still see this error?

Yes, but the cause is rarely the gateway itself: Zivv does not buffer streams, sends a keepalive every 15 seconds while the upstream is quiet, and retries or reroutes errors that occur before the first token. If you still see it, check local proxies, VPNs, the office network and any self-hosted proxy first, then find the request in the usage logs by time and check whether its status is 499 or 502.