跳轉到主要內容
設置 stream: true 即可以 Server-Sent Events 形式收到增量 token, 而不是等到最終響應。首 token 延遲降到單次網絡往返。

OpenAI 兼容(Chat / Responses)

curl -N https://api.orcarouter.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-orca-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini",
    "messages": [{"role":"user","content":"Tell me a haiku."}],
    "stream": true
  }'
每一行都是 data: {...}。流以 data: [DONE] 結尾。 如果你想拿到流中的最終 usage 對象,傳 stream_options: { include_usage: true }——[DONE] 之前的那一塊 將包含 token 計數。

Anthropic Messages

Anthropic 使用命名 SSE 事件。在 OrcaRouter 的一等公民 Anthropic 接口上,Anthropic 發出的全套事件會直接透傳:
event: message_start
event: content_block_start
event: ping
event: content_block_delta
event: content_block_stop
event: message_delta
event: message_stop
每個事件后面緊跟一行 data: {...} 的 JSON。
curl -N https://api.orcarouter.ai/v1/messages \
  -H "Authorization: Bearer sk-orca-..." \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "max_tokens": 256,
    "messages": [{"role":"user","content":"Tell me a haiku."}],
    "stream": true
  }'

流式過程中的錯誤

流中產生的錯誤無法用 HTTP 狀態碼(狀態碼在流打開時就已發出)。 參閱運維 / 錯誤 了解流中錯誤 的承載形態。

流式與回退

一旦響應的任何一個字節已經發給客戶端,OrcaRouter 就不能再切到下一個 回退條目了——詳見模型回退鏈中的流式 警示。

下一步

工具調用

流式接收工具調用的增量片段。

錯誤

處理流式過程中的失敗。