Streams that end early
A streamed response can stop at any point: the client's own read timeout fires, the network drops, the server restarts, or the service reports an error after it had already started answering. The client has to tell a stream that finished from one that merely stopped, and it has to do that without trusting the last half event it received.
What the format guarantees
The event stream specification says that when the body ends in the middle of an event, before its final empty line, that event is discarded. A parser that follows the rule never hands over half a JSON payload. A parser that flushes its buffer at the end of the body does, and the resulting JSON error then hides the real problem, which is that the connection ended.
Every format has an explicit end
Because a dropped connection and a finished response both end the body, each streaming API marks the real end with something the client can check:
| Format | Marker that the response is complete |
|---|---|
| OpenAI Chat Completions | A final data: [DONE] line |
| OpenAI Responses | A response.completed event; a response.failed event marks failure |
| Anthropic Messages | A message_stop event |
The details of each are in the format comparison. The rule is the same for all of them: if the body ends and the marker never arrived, treat the response as incomplete, however much text came through.
Errors after a 200
The status code is sent before the first event. If something goes wrong later, the server cannot change it, so the
error arrives as an event inside the stream. Anthropic's streaming documentation
shows an error event carrying an object with type and message, for example an overloaded_error; its
error reference points out that such errors do not follow the usual
status-code handling. The Responses API has an error event of its own, with code, message and param fields.
A client therefore needs two error paths: one for the status line, and one inside the event loop that turns an error event into the same exception the status path would raise.
Partial tool calls
Tool-call arguments are streamed as fragments of a JSON string. Anthropic calls them input_json_delta events with a
partial_json field; Chat Completions sends pieces of function.arguments. The fragments only form valid JSON once
the call is complete. If the stream stops in the middle, the arguments must be thrown away, not repaired and executed.
Executing a guessed argument list is how a cut connection turns into a wrong action.
Recovering
- Keep what was shown, mark it incomplete. For a chat interface, leave the partial answer visible with a clear note that it was cut off.
- Retry the whole request, not the rest of it. The
Last-Event-IDmechanism lets a browser resume a feed whose server supports it, but an ordinary streamed request to a model API is not resumed that way: a retry is a new request and the answer is generated again. If you need resumption, check whether your provider documents a separate mode for it. - Watch the gaps, not only the total. A short idle timeout between events detects a dead connection long before a
total timeout would. Comment lines and keep-alive events such as Anthropic's
pingreset that timer. - Count the cut-offs. A rising number of incomplete streams is often the first visible sign of a network or capacity problem, well before error rates move.