Skip to main content

Overview

Text generation endpoints support Server-Sent Events (SSE) streaming. Set stream: true to receive output token by token as it’s generated.

Streaming-Enabled Endpoints

  • /v1/chat/completions — OpenAI compatible
  • /v1/messages — Claude Messages
  • /v1/responses — OpenAI Responses API

Example

SSE Data Format

Each chunk is a single data: {json} SSE event:
When the stream ends, you’ll receive data: [DONE].

Final Frame Usage & Billing (cost)

The last data frame before [DONE] carries the usage and the charge of the call:
  • usage.cost is the actual quota charged for this call (integer); use it for per-call reconciliation
  • It is sent by default; explicitly passing stream_options: {"include_usage": false} disables it
  • With the OpenAI SDK, the final chunk’s chunk.usage contains this data