Skip to main content
The Responses API supports streaming responses, allowing you to receive output as it’s generated in real-time. This is particularly useful for chat interfaces and applications that need to display responses progressively.

Enabling Streaming

To enable streaming, set stream: true in your request:

Stream Event Types

The streaming API uses Server-Sent Events (SSE) format. Each event has a type field indicating the event type: Event Types:
  • response.created: Initial response creation event
  • response.output_item.added: New output item added
  • response.output_text.delta: Text delta (incremental text)
  • response.output_item.done: Output item completed
  • response.completed: Response generation completed
Example Stream Events:

Processing Stream Events

Here’s a more complete example that handles all event types:

Heartbeat Messages

The streaming API sends heartbeat messages (:ANANNAS PROCESSING) to keep the connection alive. These should be ignored when processing events.

Error Handling in Streams

Errors in streaming responses are sent as events:
Always check for error events in your stream processing:

Best Practices

  1. Handle heartbeats: Ignore :ANANNAS PROCESSING messages
  2. Check for [DONE]: Stop processing when you receive [DONE]
  3. Error handling: Always check for error events in the stream
  4. Buffer management: For long streams, consider buffering and processing in chunks
  5. Connection management: Handle connection drops gracefully and implement retry logic
Was this page helpful?