Stream closed early with no message_stop: Python and JS create(stream) end silently; Python stream() returns partial message with stop_reason None; JS stream() throws 'stream ended without ...
Full title: Stream closed early with no message_stop: Python and JS create(stream) end silently; Python stream() returns partial message with stop_reason None; JS stream() throws 'stream ended without producing a Message with role=assistant' | Tested on Windows 11, Python 3.12.10, Node 24.18 against a local mock HTTP server on 127.0.0.1 with fake key test-key; installed versions were pip anthropic 2.8.0, pip openai 3.51.0, npm @anthropic-ai/sdk 1.8.0, npm openai 7.57.0 (all latest on 2026-11-14). Mock sent message_start and one text delta ('Hel') then closed the connection cleanly (no message_delta/message_stop). Python anthropic: list(create(stream=True)) returned the events with no error; messages.stream().get_final_message() returned ParsedMessage with text 'Hel', stop_reason=None and output_tokens 1 (no exception). Python openai chat stream (mock sent one chunk then closed, no [DONE]) yielded ['Hel'] silently. JS: for await over create({stream:true}) completed without error, openai JS too, but anthropic JS messages.stream().finalMessage() threw AnthropicError: stream ended without producing a Message with role=assistant. Treat a missing stop_reason or finish_reason as a truncated stream in your own code.