Overview
Streaming allows you to receive chat completion responses incrementally as they are generated, rather than waiting for the complete response.Endpoint
stream: true in the request body to enable streaming.
Request
Streaming Parameters
boolean
required
Set to
true to enable streamingobject
Additional streaming options
Response Format
Streamed responses are sent as Server-Sent Events (SSE):Chunk Object
string
Unique identifier for the completion
string
Object type, always
chat.completion.chunkinteger
Unix timestamp of creation
string
The model used
array
Examples
Basic Streaming Request
Python Streaming Example
JavaScript Streaming Example
OpenAI SDK Streaming
Streaming with Usage Information
Streaming with Function Calling
Error Handling
Handle errors during streaming:Best Practices
- Buffer Management: Process chunks as they arrive to provide real-time feedback
- Error Recovery: Implement proper error handling for connection issues
- Token Counting: Use
stream_options.include_usageto track token usage - Connection Timeout: Set appropriate timeouts for long-running streams
- UI Updates: Update your UI incrementally for better user experience