Overview
Streaming allows you to receive response content incrementally as itβs generated, providing a better user experience for long-running requests. The Responses API supports multiple streaming patterns for different use cases.Basic Streaming
The simplest way to stream responses is using theresponses.stream method and handling events:
Key Events
ResponseTextDeltaEvent: Contains incremental text content inevent.deltaResponseTextDoneEvent: Fired when text generation is completeResponseCompletedEvent: The final event containing the full response object
Simplified Text Streaming
For cases where you only need the text content, use the.text helper method:
The
.text method provides a simplified iterator that yields only text deltas, filtering out other event types automatically.Streaming with Tools
Stream function call arguments as theyβre generated:Tool Streaming Events
ResponseFunctionCallArgumentsDeltaEvent: Contains:event.delta: The incremental JSON string fragmentevent.snapshot: The accumulated JSON so far
The
snapshot field is particularly useful for displaying partial function arguments to users as theyβre being generated.Resuming Streams from Previous Responses
You can pause and resume streaming responses usingprevious_response_id and starting_after:
Create a background streaming response
Start a stream with
background: true to allow it to continue processing server-side:Capture the response ID and last sequence number
Process events until you want to pause, capturing the response ID and last sequence number:
Resuming with Structured Outputs
When resuming a stream that uses structured outputs, you must pass the sametext parameter:
The
background: true option allows the response to continue processing on the server even after you stop consuming events, enabling efficient pause-and-resume patterns.