Streaming
Set stream: true to receive tokens as they are produced, rather than waiting
for the complete response.
curl https://api.resetdata.ai/api/v1/chat/completions \ -H "Authorization: Bearer $RESETDATA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "zai/glm-5.2", "messages": [{ "role": "user", "content": "Write a haiku about Sydney." }], "stream": true }'stream = client.chat.completions.create( model="zai/glm-5.2", messages=[{"role": "user", "content": "Write a haiku about Sydney."}], stream=True,)
for chunk in stream: if not chunk.choices: continue delta = chunk.choices[0].delta.content if delta: print(delta, end="", flush=True)const stream = await client.chat.completions.create({ model: "zai/glm-5.2", messages: [{ role: "user", content: "Write a haiku about Sydney." }], stream: true,});
for await (const chunk of stream) { const delta = chunk.choices[0]?.delta?.content; if (delta) process.stdout.write(delta);}The response
Section titled “The response”Server-sent events, each a chat.completion.chunk carrying an incremental
delta, terminated by data: [DONE]. Any OpenAI-compatible SDK parses this for
you.
Reassemble by concatenating choices[0].delta.content across chunks. The first
chunk typically carries the role rather than content, and the final chunk carries
finish_reason — so check for null content rather than assuming every chunk
has text. Some models also emit a final chunk with an empty choices array
(the usage/terminator chunk), so guard choices[0] before indexing it, as the
examples above do.
Why streaming is worth using
Section titled “Why streaming is worth using”Beyond appearing faster, streaming has a real operational advantage: once tokens are flowing you have continuous evidence the request is alive.
A non-streaming request to a busy model can sit silent for a long time — first waiting in the queue, then generating. Intermediate proxies are far more willing to cut a silent connection than an active one.
Token usage while streaming
Section titled “Token usage while streaming”Ask for usage explicitly if you want it in the stream:
{ "stream": true, "stream_options": { "include_usage": true } }This appends a final chunk carrying token counts. Support varies by model — check
supported_parameters per Model parameters. Either way,
the request is billed identically; this only affects whether the counts come back
inline. Your authoritative record is always
Usage.
Handling disconnects
Section titled “Handling disconnects”If the connection drops mid-stream you keep the partial text but there is no way to resume — a retry starts a new generation, and is billed as one. For long generations, persist chunks as they arrive so a failure late in a response doesn’t discard everything before it.