LLM API Guide

API Error: Response stalled mid-stream. The response above may be incomplete

The stream stopped delivering data partway through the reply, so Claude Code kept the finished part and stopped. Reply continue to resume; if it repeats, check the network path.

Summary

  1. Since v2.1.227 the same failure reads The response stopped arriving. The response above may be incomplete.
  2. Claude Code does not resend the request at that point, because that could run the same tool calls twice; it keeps every completed block.
  3. The last sentence or tool call may be missing, so check the output and reply continue.
  4. Before v2.1.222, gateways reached through ANTHROPIC_BASE_URL could trigger spurious stalls while keep-alive pings still arrived; update.
On this page

The stream went quiet partway through

text
API Error: Response stalled mid-stream. The response above may be incomplete.

The connection stayed open but stopped delivering data, so Claude Code's streaming idle watchdog aborted it. Because Claude had already finished a block of text or a tool call, Claude Code did not resend the request; that could run the same tool calls twice. It kept every completed block, ran any tool calls Claude had finished, and added this notice.

The Claude Code error reference lists this under "The response above may be incomplete". From v2.1.227 the wording is The response stopped arriving. The response above may be incomplete.; Response stalled mid-stream is the older text. Related variants name other causes: Connection lost mid-response, Server error mid-response and Your computer went to sleep mid-response.

Pick up where it stopped

In an interactive session:

  1. Read what is on screen. Claude Code keeps completed blocks but drops an interrupted final block, so the last sentences or tool calls may be missing.
  2. Reply continue. Claude picks up from its last completed block.

In -p runs, Claude Code prints the last completed text block it still has, then this message; with --output-format json or stream-json the message is in result. Resume the session and send continue once the connection is stable. Since v2.1.246, non-interactive sessions and subagents first ask Claude to continue a cut-off text reply up to three times by themselves, and you see the notice only when those run out.

When the message says your computer went to sleep

text
API Error: Your computer went to sleep mid-response. The response above may be incomplete.

This wording appears when the machine slept or suspended while a response was streaming. According to the Claude Code error reference, Claude Code treats the connection as broken after the machine wakes and stops reading from it. It is not a gateway or server fault. Claude Code keeps what Claude had finished, runs the tool calls that completed and does not resend the request, so the fix is the same as above: check the last output and reply continue. The mid-response notices were added in v2.1.199; before that, a server error partway through a stream discarded the partial output.

For long runs, keep the machine awake. On macOS, caffeinate -i holds off idle sleep for as long as the command it wraps is running (caffeinate syntax):

bash
caffeinate -i claude

If it keeps happening

When it repeats, check in this order:

  • Your Claude Code version. Before v2.1.222, sessions behind a gateway set in ANTHROPIC_BASE_URL or ANTHROPIC_AWS_BASE_URL could report a stall while the server's keep-alive pings were still arriving, because only parsed events counted. Run claude update.
  • The path between you and the API. If you go through a proxy, VPN or gateway, try once without it to see whether the stalls follow it.
  • A computer that sleeps during long replies shows up as Your computer went to sleep mid-response; keep it awake for long runs.

If a gateway legitimately pauses longer than the watchdog allows, raise the timeout. Claude Code's network configuration page gives the defaults (180 seconds for the byte-level watchdog on the direct API, 300 seconds through a custom ANTHROPIC_BASE_URL, 300 seconds for the event-level watchdog) and the variable:

bash
export CLAUDE_STREAM_IDLE_TIMEOUT_MS=<milliseconds>

Claude Code raises values below 5 minutes to 5 minutes and caps the byte-level watchdog at 30 minutes. A higher value also means a dead connection takes longer to fail, so check the path first.

A failed turn can leave a stray entry in the session that breaks the next request; if you then see a 400 about diagnostics.previous_message_id, that page covers the repair. To check what a relay does to your stream and requests, see how to check that an LLM API relay serves the model you pay for. Other errors are on our Claude Code API Error 400 page.

Sources and checks

  1. Claude Code error reference
  2. Claude Code network configuration (streaming idle watchdogs)
  3. Claude Code error reference (mid-response notices)
  4. caffeinate man page (macOS)