documentation
streaming
Receive output as it is generated with server-sent events.stream chat deltas
Set stream=True. The official SDK parses each server-sent event and yields typed chunks.
stream = client.chat.completions.create(
model="brok-2.3-fast",
messages=[{"role": "user", "content": "Explain SSE briefly."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)stream response events
with client.responses.stream(
model="brok-2.3",
input="Give me three product names.",
) as stream:
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)Key event types are response.created, response.output_text.delta, and response.completed.
connection behavior
For chat completions, read each data: line until [DONE]. For Responses, dispatch using the event: name. Do not buffer the entire HTTP body in a proxy. Streaming usage is finalized after the stream closes and then appears in Usage.