Streaming
Set stream: true to receive the answer incrementally as
server-sent events.
Streaming works on every endpoint: Chat Completions, Responses, Anthropic
Messages and Gemini.
stream = client.chat.completions.create( model="gpt-5.6-luna", messages=[{"role": "user", "content": "Count from 1 to 5."}], stream=True, stream_options={"include_usage": True},)for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) if chunk.usage: print("\n", chunk.usage)const stream = await client.chat.completions.create({ model: "gpt-5.6-luna", messages: [{ role: "user", content: "Count from 1 to 5." }], stream: true, stream_options: { include_usage: true },});for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? "");}curl -N https://api.wraitherix.com/v1/chat/completions \ -H "Authorization: Bearer $WRAITHERIX_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-5.6-luna","stream":true, "messages":[{"role":"user","content":"Count from 1 to 5."}]}'Wire format
Section titled “Wire format”Each event is a data: line with a chat.completion.chunk object. The stream
ends with data: [DONE]:
data: {"id":"resp_0bcb…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"1"}}]}
data: {"id":"resp_0bcb…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":", 2"}}]}
data: {"id":"resp_0bcb…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":14,"completion_tokens":9,"total_tokens":23}}
data: [DONE]Add "stream_options": {"include_usage": true} to receive a final chunk with
token usage.
- Use
curl -N(no buffering) when testing from the terminal. - If you proxy the stream through your own server, disable response buffering
(e.g.
X-Accel-Buffering: noon nginx). - A stream that is interrupted by the client is billed only for the tokens generated so far.