Streaming
Set stream: trueto receive the completion as Server-Sent Events. The platform forwards the provider's stream and aggregates the final usage payload so the cost is auditable. Firewalls and tools work identically in streaming mode.
Request field
Streaming is controlled by a top-level boolean on the request. The OpenAI SDK exposes it as a native parameter; raw HTTP clients set it directly in the body.
1from openai import OpenAI
2
3client = OpenAI(
4 base_url="https://api.qdiv0.com/v1",
5 api_key="your-api-key",
6)
7
8stream = client.chat.completions.create(
9 model="qwen35-demo",
10 messages=[{"role": "user", "content": "Tell me a story"}],
11 stream=True,
12 extra_body={"firewall": "strict-block"},
13)
14for chunk in stream:
15 if chunk.choices[0].delta.content:
16 print(chunk.choices[0].delta.content, end="")1curl https://api.qdiv0.com/v1/chat/completions \
2 -H "Authorization: Bearer $QDIV0_API_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "model": "qwen35-demo",
6 "messages": [{"role": "user", "content": "Tell me a story"}],
7 "stream": true
8 }'Server-Sent Events
The response uses the standard OpenAI Server-Sent Events format. Each line is a JSON-encoded chat.completion.chunk object with a delta of the response. The stream terminates with a final data: [DONE] sentinel. Most OpenAI SDKs handle this automatically and surface chunks through a normal iterator.
The first chunk includes the role ("assistant"); subsequent chunks include content deltas; tool calls appear as tool_calls deltas. If you have attached a platform tool, the platform handles the call inside the stream and you will see the formatted results appear as additional chunks before the final model response.
Usage and billing
The final chunk of a stream includes a usage object with the aggregated prompt, completion, and total token counts. The platform uses the same object to write a ledger entry on your account, so the cost is fully auditable even when the response is consumed incrementally. Firewalls and tools are billed in the same way whether you stream or not.