Streaming and reasoning
Read incremental text, handle terminal events and collect usage.
Enable a stream
Set stream: true in the request. Chat Completions, Responses, legacy Completions and Messages use server-sent events. Ollama-compatible endpoints stream newline-delimited JSON.
curl --no-buffer --fail-with-body -sS https://site6.eokgg.win/v1/chat/completions \
-H "Authorization: Bearer $SITE6_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "deepseek-v4.1-flash-1017",
"messages": [{"role": "user", "content": "Write three short sentences about caching."}],
"stream": true,
"stream_options": {"include_usage": true},
"max_tokens": 256
}'Collect text and handle completion
| Endpoint | Text arrives in | Terminal signal |
|---|---|---|
| Chat Completions | choices[].delta.content |
finish_reason followed by [DONE] |
| Responses | response.output_text.delta events |
response.completed or response.incomplete |
| Messages | content_block_delta events |
message_stop |
| Legacy Completions | choices[].text |
finish_reason followed by [DONE] |
| Ollama | message.content or response |
JSON record with done: true |
An SSE read can contain part of an event or several events. Split complete SSE events before parsing their JSON. Collect tool arguments by their call ID or tool index, then parse the complete argument object. Surface an error event even when the HTTP status was already 200.
X-Site6-Stream-Mode reports incremental or buffered. Requests that need a validated structured result, a hosted tool result or several choices may buffer some or all of the response. Cancel the client’s request to release its active slot and cancel work that can still be stopped.
Reasoning and usage
Use thinking: true or a model’s supported reasoning_effort to request reasoning. Chat can include reasoning_content and Responses can return a reasoning item. Keep reasoning separate from final answer text. reasoning_metadata reports the mode and measured counts when available. thinking: false suppresses reasoning output.
Usage in a Chat stream is available on the final usage chunk when stream_options.include_usage is enabled. Responses puts final usage on its completed response. A null or missing count means the complete count is unavailable.