Skip to content

Streaming

Streaming (v2 & v3)

Set stream: true untuk menerima response secara streaming lewat SSE. Berlaku untuk /v2/chat/completions dan /v3/chat/completions (juga /messages & /responses di v3).

Terminal window
# v3
curl https://balitechsolution.com/v3/chat/completions \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "bt/qwen3.8-flash",
"messages": [{"role": "user", "content": "Ceritakan tentang AI"}],
"stream": true,
"stream_options": {"include_usage": true}
}'
# v2 — sama, ganti path
curl https://balitechsolution.com/v2/chat/completions \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "bt/qwen3.8-flash",
"messages": [{"role": "user", "content": "Ceritakan tentang AI"}],
"stream": true,
"stream_options": {"include_usage": true}
}'

Event format

data: {"choices":[{"delta":{"content":"Halo"}}]}
data: {"choices":[{"delta":{"content":" dunia"}}]}
data: [DONE]

Usage di stream

Tambah stream_options: { include_usage: true } untuk dapat info token di chunk akhir. Proxy v2 & v3 auto-inject include_usage kalau kamu lupa, tapi set eksplisit lebih aman.

Settings lengkap (backpressure MAX_CONCURRENT, fallback header, dsb): Settings API.