Skip to main content
Set stream: true to receive typed events as they arrive. The SDK handles SSE framing, partial chunks, and the final usage event for you.

Request

Code examples

SSE format

Both endpoints stream text/event-stream. While the gateway waits for the first token from a provider it may send comment frames — lines that begin with : — as keepalives. They carry no data: a spec-compliant SSE parser ignores them, and a hand-rolled parser must skip any line starting with : rather than trying to parse it as JSON.

Responses

Each frame carries an event: name and a data: JSON object whose type repeats the name and whose sequence_number increases monotonically:
The stream closes after response.completed; there is no [DONE] sentinel on this endpoint.

Chat Completions

OpenAI-compatible chat.completion.chunk objects on data: lines, ending with data: [DONE]:
The final chunk — empty delta, finish_reason set — always carries the request receipt, whether or not you set stream_options.include_usage:
If a provider fails after the HTTP status has been sent, the last data frame before [DONE] is an error object instead: partial_stream when some output was already delivered (only the delivered tokens are billed) or stream_error when nothing was (you are not charged).

Billing

  • Streaming uses the same metered rates as a non-streaming request and settles on the actual usage reported in the final frame.
  • If you abort the connection mid-stream, only the tokens delivered before the abort are billed.

Notes

  • Use the SDK unless you specifically need to own the SSE parser.
  • Abort TypeScript streams with AbortSignal in the request options.