"stream": true to receive the response incrementally as Server-Sent Events
(SSE). Pass -N (or --no-buffer) to curl so it prints chunks as they arrive.
Read a stream with Python
Installopenai and set IMPOSSIBL_API_KEY as in the quickstart.
choices array. Check it before indexing.
A stream can fail after HTTP
200. Handle SDK exceptions and incomplete output; a connection closing is not proof of success. See streaming errors.Chat Completions
cURL and Chat Completions events
cURL and Chat Completions events
Each event is a line
data: <json> carrying a chat.completion.chunk:Stream (abridged)
- First chunk →
delta.role: "assistant",finish_reason: null - Content chunks →
delta.contentholds the next token(s) - Final chunk → empty
delta,finish_reasonset (stop,length, …) - Usage chunk → only when
stream_options.include_usageistrue; it has an emptychoicesarray and ausageobject - Terminator →
data: [DONE]
choices[0].delta.content only when choices is nonempty and the delta contains text. Because the
gateway emits the exact OpenAI shape, client.chat.completions.create(..., stream=True)
in any OpenAI SDK works unchanged.Responses API
Show request format
Show request format
The Responses API streams semantic events instead of generic chunks. Each
event has both an For a text-only response, events arrive in this order:
event: line and a data: line, and a monotonically
increasing sequence_number.Aggregate the
delta fields from response.output_text.delta events to build the
text; read final token usage from response.completed.When the model reasons, a reasoning item comes first, at output_index 0, and the
message item follows at the next index. Its summary events appear only when the
request sets reasoning.summary; each reasoning block is one summary part
(summary_index):See reasoning for the item’s shape.
Messages (Anthropic)
Show request format
Show request format
POST /v1/messages streams Anthropic’s semantic events, so the official
anthropic SDK’s client.messages.stream(...) works unchanged. Like the
Responses API, each event has an event: line and a data: line. (A bare
claude-... model id routes to Anthropic; any provider/model id also works
here — see SDKs & integrations.)Concatenate
delta.text from content_block_delta events to build the output;
read the final token usage (and stop_reason) from message_delta. Note the
usage on message_start is zeroed — real token counts are only known at the end.
