Docs / API reference

Streaming

Stream tokens as they are generated with server-sent events.

Enabling

Set stream to true. The response arrives as SSE data lines with incremental deltas; a final data: [DONE] line closes the stream.

Python
stream = client.chat.completions.create(
    model="google/gemini-3.8-flash",
    messages=[{"role": "user", "content": "Count to ten"}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)

Streaming is billed identically to non-streaming. Usage accounting is attached to the final chunk where supported.