CheapAI
Blog

An AI stream ended after HTTP 200. Did the response finish?

Inspect the final stream event, distinguish an output limit from a disconnect, and decide whether retrying a tool call could duplicate work.

Your client prints half a file, pauses and starts again from the first line. Both requests show HTTP 200. Headers arrived before the first token, so that status tells you little about the end of the response.

Read the final event

In native Anthropic Messages, inspect stop_reason on message_delta and look for message_stop. In OpenAI-compatible Chat Completions, check finish_reason and the SSE termination specified by your provider. A length finish indicates an output limit. A socket closing in the middle of a JSON fragment leaves the cause open.

Capture a useful trace

Record the request ID, send time, first text time, final event type and time. Compare a short generation and a long one in the same client. A disconnect after a consistent idle interval is a reason to inspect client and proxy idle timeouts. If timing varies, send both traces to support without including your repository contents.

Check for side effects before retrying

A fresh text generation may be fine. A tool that already created an order or sent a message needs a state check before another attempt. Losing the final stream event does not undo an action that already ran.

Anthropic Messages · API errors

Worked examples