Skip to main content
ARouter supports streaming responses for all models. When streaming is enabled, tokens are delivered in real time as they’re generated. To enable streaming, set stream: true in your request body.

Anthropic Streaming

The Anthropic SDK uses its own streaming format:

Gemini Streaming

Gemini uses streamGenerateContent instead of generateContent:

SSE Format

Under the hood, streaming uses Server-Sent Events. Each content event looks like:
The final chunk before [DONE] contains usage data with an empty choices array:
ARouter may occasionally send SSE comments (lines starting with :) to prevent connection timeouts. These can be safely ignored per the SSE specification.
Some SSE client implementations may not parse the payload correctly. We recommend:

Stream Cancellation

Streaming requests can be cancelled by aborting the connection. For supported providers, this immediately stops model processing.

Handling Errors During Streaming

ARouter handles errors differently depending on when they occur during the streaming process.

Errors Before Any Tokens Are Sent

If an error occurs before any tokens have been streamed, ARouter returns a standard JSON error response with the appropriate HTTP status code:
Common HTTP status codes:

Errors After Tokens Have Been Sent (Mid-Stream)

If an error occurs after some tokens have already been streamed, ARouter cannot change the HTTP status code (which is already 200 OK). Instead, the error is sent as an SSE event:
Key characteristics:
  • The error appears at the top level alongside standard response fields
  • A choices array is included with finish_reason: "error" to terminate the stream
  • The HTTP status remains 200 OK since headers were already sent

Error Handling Code Examples