Streaming
Stream responses incrementally using server-sent events (SSE). By setting stream: true, the application processes delta events as they arrive, significantly reducing time to first token. Streaming is available only for models and endpoints that support it.
Examples
SSE format
Each streamed chunk is a data: event containing a JSON payload. The text delta normally arrives through choices[0].delta.content. The stream ends when the server closes the SSE connection. OpenAI-compatible clients may also receive a data: [DONE] terminal event when provided by the upstream stream.
Illustrative stream output. The data: [DONE] terminal event appears only when it is provided by the upstream stream.
Errors and cancellation
Stopping a stream
The client may abort the HTTP request at any time using an AbortController (in JS) or the SDK's supported cancellation mechanism.
Stream errors
Errors may occur before or during streaming. Applications should handle network interruptions gracefully, keeping in mind that partial output may have already been received.