Skip to content

Streaming

Set stream: true to receive tokens as they are produced, rather than waiting for the complete response.

Terminal window
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
}'

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.

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.

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.

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.