Streaming
Set "stream": true to receive the response as it is generated, as server-sent events in the OpenAI format. Streaming works with tool calls.
Request
curl -N https://API_HOST/v1/chat/completions \
-H "Authorization: Bearer $UI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "MODEL_ID", "stream": true,
"messages": [{"role": "user", "content": "Hello"}]}'
Event format
Each event is a line starting with data: followed by a JSON chunk. The stream ends with
data: [DONE].
data: {"choices":[{"index":0,"delta":{"role":"assistant","content":"Hel"}}]}
data: {"choices":[{"index":0,"delta":{"content":"lo"}}]}
data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
Python
stream = client.chat.completions.create(
model="MODEL_ID",
messages=[{"role": "user", "content": "Hello"}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Node.js
const stream = await client.chat.completions.create({
model: "MODEL_ID",
messages: [{ role: "user", content: "Hello" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
Practical notes
- Disable response buffering in any proxy between your client and the API.
- Set a read timeout that tolerates long generations.
- If the connection drops, the generation is lost: content is not stored on our side. Send the request again.
Last updated: 2 December 2026