TheaimartAIx DOCS
Home Get API key

Streaming

Set stream: true to receive standard OpenAI server-sent events (SSE), terminated by [DONE].

Python

stream = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3.2",
    messages=[{"role": "user", "content": "count to 5"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

Node / TypeScript

const stream = await client.chat.completions.create({
  model: "deepseek-ai/DeepSeek-V3.2",
  messages: [{ role: "user", content: "count to 5" }],
  stream: true,
});
for await (const part of stream) {
  process.stdout.write(part.choices[0]?.delta?.content ?? "");
}

Wire format

Responses are text/event-stream of chat.completion.chunk events:

data: {"object":"chat.completion.chunk","choices":[{"delta":{"content":"1"}}]}
data: {"object":"chat.completion.chunk","choices":[{"delta":{"content":" 2"}}]}

data: {"object":"chat.completion.chunk","choices":[{"delta":{},"finish_reason":"stop"}]}
data: [DONE]

Behaviour & billing

  • Stream-native models emit token-by-token through standard OpenAI SSE chunks.
  • Buffered models return a final valid SSE chunk, so your client code stays identical.
  • Failover happens on connect: if the selected route cannot start the stream, AIx tries the next eligible path. Once bytes flow, that route serves the whole stream.
  • Usage is settled when the stream ends — billed on real tokens, refunded if the up-front estimate was high.

For coding agents, streaming gives you first-token latency — start rendering the diff while the model is still writing it.

Last updated July 18, 2026

Was this page helpful?