altrouter.ai
CORE

Streaming

Set stream: true to receive the reply token-by-token as OpenAI-compatible server-sent events (SSE).

How it works

Each event is a data: {...} line carrying a chat.completion.chunk. The stream ends with data: [DONE]. Reasoning-model tokens arrive in delta.reasoning_content.

PythonJavaScriptcURL
stream = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "Write a haiku"}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta
    if delta.content:
        print(delta.content, end="", flush=True)
i
Failover is only possible before the first byte. Once the first event reaches the client the response is committed to the current route, and a later error surfaces in-stream as an error event.

Usage & tokens

The final chunk carries a usage object with token counts. Billing settles on actual usage after the stream completes.

NextStructured outputs