Streaming

Streaming

Set stream: true to receive server-sent events as the model writes.

Stream a reply

Thinking arrives in choices[0].delta.reasoning_content, the answer in choices[0].delta.content, and the stream ends with [DONE]. Add "stream_options": {"include_usage": true} to get token usage in the final chunk.

Python
stream = client.chat.completions.create(
    model="deepseek-v4.1-flash-1017-uncensored",
    messages=[{"role": "user", "content": "Write a haiku about the sea."}],
    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)