"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.
Chat Completions
Each event is a linedata: <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. 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 anevent: 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.
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.)
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.
