Skip to content
laminarity

API

Streaming

Set "stream": true and tokens arrive as server-sent events while the model writes, exactly like the OpenAI API.

stream = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Flash-0731",
    messages=[{"role": "user", "content": "Write a haiku about rivers."}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

Event format

  • Each event is a line data: {…} with a chat completion chunk; the text is in choices[0].delta.content.
  • The stream ends with data: [DONE].
  • Lines that start with a colon are keep-alive comments sent during long pauses. OpenAI SDKs skip them; custom parsers should too.
With curl use -N so output is not buffered.