Skip to content

Потоковые ответы

Потоковый вывод RouteAPI использует Server-Sent Events (SSE). Установите stream: true, чтобы получать контент постепенно.

Terminal window
curl https://www.routeapi.ai/v1/chat/completions \
-H "Authorization: Bearer $ROUTEAPI_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","stream":true,"messages":[{"role":"user","content":"Explain streaming"}]}'
data: {"choices":[{"delta":{"content":"RouteAPI"}}]}
data: {"choices":[{"delta":{"content":" supports"}}]}
data: [DONE]

Read data: line by line and stop after [DONE].

{"stream":true,"stream_options":{"include_usage":true}}

Support depends on model capability.

  • Model service timeout
  • Insufficient quota
  • Network interruption
  • Client disconnect
  • Tool call parameter generation failure

Рекомендации:

  1. Record request id.
  2. Use limited retries for network interruption.
  3. Avoid retrying operations with side effects.
  4. Check console usage logs.