Streaming
Receive completion tokens over Server-Sent Events.
Request Fields
| Name | Type | Required | Description |
|---|---|---|---|
stream | boolean | Optional, defaults to false. Set true for SSE. | |
stream_options.include_usage | boolean | Must be true to emit the final usage chunk. |
SSE Event Flow
text
data: {"id":"chatcmpl_...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl_...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl_...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"req_123","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":10,"completion_tokens":2,"total_tokens":12}}
data: [DONE]Usage Chunk
Usage is emitted as a separate final chunk with
choices: [] only when stream_options.include_usage is enabled.