Skip to content

Streaming Responses

RouteAPI streaming output uses Server-Sent Events (SSE). After setting stream: true in the request, the server returns incremental content step by step.

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 output step by step" }
]
}'
data: {"id":"chatcmpl_xxx","choices":[{"delta":{"content":"RouteAPI"}}]}
data: {"id":"chatcmpl_xxx","choices":[{"delta":{"content":" supports"}}]}
data: [DONE]

Clients should read data: line by line and end the response after receiving [DONE].

If the current model supports it, streaming requests can ask for final usage through stream_options:

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

Support for this field depends on the selected model and service capability.

Streaming requests may encounter service-side errors after the connection is established, such as:

  • Model service timeout
  • Insufficient account quota
  • Network interruption
  • Client closes the connection actively
  • Tool call parameter generation failure

Recommended client behavior:

  1. Record a request id for every request.
  2. Retry network interruptions only with limits.
  3. Avoid automatically retrying tool calls that have already produced side effects.
  4. Use console usage logs to troubleshoot service-side errors.