Enable SSE#
Set stream: true and stream_options: { include_usage: true }. Read each data line as JSON; append choices[0].delta.content when present. Do not assume a network chunk is one event.
Finish and usage#
A finish_reason closes the choice; the final usage frame may arrive separately. Stop only on [DONE] or a terminal error. Retain usage totals rather than estimating tokens from characters.
Interrupted requests#
The gateway keeps a billing reservation until authoritative provider usage is available. A browser disconnect is not proof the provider stopped generating. If final usage is missing, the reservation remains pending reconciliation instead of silently charging an estimate.
Browser delivery#
Keep the API key on a server. Use your own same-origin endpoint to forward SSE to the browser; see the browser streaming recipe.
Request example
curl https://weightsapi.com/v1/chat/completions \
-H "Authorization: Bearer $WEIGHTSAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3-32B",
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"stream": true
}'