Skip to Content
hackrouter

Streaming

Server-sent events in each API's own format, and what a broken stream costs.

Set stream: true as you would with OpenAI or Anthropic. Events arrive in the format of the API you called, with your model ID.

  • Keepalive. A comment line, : keepalive, is sent every 15 seconds while the model is quiet, so proxies do not close the connection.
  • Usage in the stream. On Chat Completions, set stream_options.include_usage to get the usage in a final chunk. The request is charged on that usage either way.
  • A broken stream. If the provider fails after the answer has started, the stream ends with an error event whose code is stream_broken. It is not retried. You pay for what was sent.
  • Disconnecting. If you close the connection partway, the answer stops and you pay for what was generated up to then.

Before the first byte, a failing provider is replaced by another route, so a stream that has started comes from one model and one answer.