无需等待最后一个 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
}'