Streaming
With "stream": true, the answer arrives as server-sent events (Content-Type: text/event-stream) as the PC writes it. Each event is a line data: <JSON> followed by an empty line, and the stream ends with data: [DONE].
curl -N https://app.noduma.dev/v1/chat/completions \ -H "Authorization: Bearer $NODUMA_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "qwen2.5-7b-instruct-q4_k_m", "stream": true, "messages": [{"role": "user", "content": "Count to five."}]}'stream = client.chat.completions.create( model="qwen2.5-7b-instruct-q4_k_m", messages=[{"role": "user", "content": "Count to five."}], stream=True,)for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True)const stream = await client.chat.completions.create({ model: 'qwen2.5-7b-instruct-q4_k_m', messages: [{ role: 'user', content: 'Count to five.' }], stream: true,});for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? '');The events
Section titled “The events”data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1764460800,"model":"qwen2.5-7b-instruct-q4_k_m","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk", ... "choices":[{"index":0,"delta":{"content":"One, two"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk", ... "choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":14,"completion_tokens":12,"total_tokens":26,"noduma_cost":15,"noduma_price_per_1k_tokens":1000}}
data: [DONE]- The first chunk carries the role.
- Text chunks carry
delta.content. - When the answer calls tools, one chunk carries all
delta.tool_calls, each with itsindex,id,typeandfunction. - The last chunk before
[DONE]carriesfinish_reasonandusage, with the answer's cost. You need not ask for it withstream_options.
The response headers include Noduma-Routing, the routing mode used, and Cache-Control: no-store.
Errors
Section titled “Errors”- Before the first chunk, an error is an ordinary JSON error with its HTTP status, as without streaming.
- After the stream started, an error arrives as an event,
data: {"error": {"message": "...", "type": "...", "code": "..."}}, and the stream ends. The status is already200, so read the events.
When a PC fails mid-answer
Section titled “When a PC fails mid-answer”If the PC that answers fails, the coordinator moves the request to another PC serving the model that can continue an answer, and that PC continues it from where it stopped: you see a pause, not a repeat. When no PC can continue it, the stream ends with an error event.
Proxies
Section titled “Proxies”If you put a proxy in front of your client, it must not buffer the event stream. Noduma's own answers carry X-Accel-Buffering: no for nginx.