Loading
Skip to content
RedRouterRedRouter
Dashboard ↗

Streaming

Non-streaming requests have a 110-second total deadline and return 504 on timeout. Use stream: true for long generations. Idle streams send keepalives every 15 seconds. Reported usage is billed; missing usage is reconciled before any charge.

Set stream: true. Read the response as server-sent events; a network chunk may contain part of an event or several events.

Chat Completions

curl -N -X POST 'https://redrouter.org/v1/chat/completions' \
  -H "Authorization: Bearer $REDROUTER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "messages": [
    {
      "content": "Hello",
      "role": "user"
    }
  ],
  "model": "glm-5.3-flash-rr",
  "stream": true,
  "stream_options": {
    "include_usage": true
  }
}'

Read each data field as JSON. Text arrives in choices[].delta.content. Tool arguments arrive as fragments. Assemble them before parsing JSON.

Set stream_options: { include_usage: true } to request a terminal usage chunk. Continue after finish_reason until data: [DONE]. Usage may arrive after the finish reason.

Messages

Read named events: ping, message_start, content_block_start, content_block_delta, content_block_stop, message_delta, and message_stop. Errors arrive as error events.

Text deltas use text_delta. Tool input deltas use input_json_delta. Read through message_stop.

Handle disconnects

Close the connection to cancel generation. If the stream ends unexpectedly, check account usage before retrying. Missing usage enters reconciliation; RedRouter does not invent token counts.

↑ ↓ to select · Enter to open · Esc to close