Skip to main content
Set "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

Install openai and set IMPOSSIBL_API_KEY as in the quickstart.
The usage chunk can have an empty 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

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.content holds the next token(s)
  • Final chunk → empty delta, finish_reason set (stop, length, …)
  • Usage chunk → only when stream_options.include_usage is true; it has an empty choices array and a usage object
  • Terminator → data: [DONE]
To reassemble the text, concatenate 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

The Responses API streams semantic events instead of generic chunks. Each event has both an event: line and a data: line, and a monotonically increasing sequence_number.
For a text-only response, events arrive in this order: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)

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.)
For a text-only response, events arrive in this order: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.