API
Streaming
Set stream: true to receive the response incrementally over SSE.
With "stream": true in the request body, the server responds with server-sent events. Each line starts with data: followed by a JSON chunk; the final line is data: [DONE].
data: {"id":"chatcmpl-3f9a…","object":"chat.completion.chunk","model":"deepseek-v4.1-flash-heretic","choices":[{"index":0,"delta":{"role":"assistant","content":"Hel"}}]}
data: {"id":"chatcmpl-3f9a…","object":"chat.completion.chunk","model":"deepseek-v4.1-flash-heretic","choices":[{"index":0,"delta":{"content":"lo"}}]}
data: {"id":"chatcmpl-3f9a…","object":"chat.completion.chunk","model":"deepseek-v4.1-flash-heretic","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":2}}
data: [DONE]All chunks of one request share the same id. Concatenate choices[0].delta.content from each chunk to get the full reply.
Python
stream = client.chat.completions.create(
model="deepseek-v4.1-flash-heretic",
messages=[{"role": "user", "content": "Tell me a short story"}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)Notes
- Lines that start with a colon are keep-alive comments. Ignore them.
- If an error occurs mid-stream, you receive a data line containing an error object in the same format as non-streaming errors.
- For reasoning models, the reasoning may arrive in delta.reasoning_content while the answer stays in delta.content.