開啟 SSE 串流
啟用 stream: true 並停用用戶端緩衝。伺服器會在回覆各部分可用時傳送資料事件。
逐步處理串流:單一事件不一定包含完整文字或完整工具呼叫。
SSE 串流
bash
curl --no-buffer --request POST https://cicora.ai/api/v1/chat/completions \
--header "Authorization: Bearer $CICORA_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "openai/gpt-5.6-sol",
"stream": true,
"stream_options": {"include_usage": true},
"messages": [{"role": "user", "content": "Write a three-line poem."}]
}'組合增量
- 依 choice/index 或項目識別碼累積文字。
- 以 JSON 片段串流收集工具引數,並在完成後解析。
- 若最終指標很重要,請在串流中明確啟用可用的 usage 選項。
完成與取消
只有在終止事件發生後才將串流視為完成。連線在沒有終止事件時關閉,屬於不同的失敗路徑。
將 AbortController 或同等機制連接到使用者導覽,避免不再使用的請求持續開啟。