無需等待最後一個 token。
設定 stream: true 以接收伺服器傳送事件。每個事件的 data: 欄位包含一個 completion 資料區塊。資料流以 data: [DONE].
data: {"choices":[{"delta":{"content":"Hello"}}]}
data: {"choices":[{"delta":{"content":" there."}}]}
data: [DONE]這是協定示意片段,不是真實 API 回應或用量記錄。
明確處理連線中斷
不要自動重播已部分接收的資料流。連線中斷不一定代表模型停止生成。重試計費請求前,請先檢查請求記錄和 trace ID。
curl https://unlimit.chat/v1/chat/completions \
-H "Authorization: Bearer $UNLIMIT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_MODEL_ID",
"messages": [
{"role": "user", "content": "What if we built something different?"}
],
"stream": true
}'