Streaming

Stream responses in real-time with multiple consumption patterns. All streams are built on a reusable stream architecture that supports concurrent consumers.

Text Streaming

getTextStream()

Stream text content as it’s generated:

Each iteration yields a small chunk of text (typically a few characters or a word).

Reasoning Streaming

getReasoningStream()

For models that support reasoning (like o1 or Claude with thinking), stream the reasoning process:

Items Streaming

getItemsStream()

Stream complete items as they update. This is the recommended way to handle streaming when you need structured access to all output types (messages, tool calls, reasoning, etc.). See Working with Items for the full paradigm explanation.

Key insight: Each iteration yields a complete item with the same ID but updated content. Replace items by ID rather than accumulating deltas.

This stream yields all item types:

TypeDescription
messageAssistant text responses
function_callTool invocations with arguments
reasoningModel thinking (extended thinking)
web_search_callWeb search operations
file_search_callFile search operations
image_generation_callImage generation operations
function_call_outputResults from executed tools

Message Streaming (Deprecated)

getNewMessagesStream()

getNewMessagesStream() is deprecated. Use getItemsStream() instead, which includes all item types and follows the items-based paradigm.

Stream incremental message updates in the OpenResponses format:

This stream yields:

  • ResponsesOutputMessage - Assistant text/content updates
  • OpenResponsesFunctionCallOutput - Tool execution results (after tools complete)

Full Event Streaming

getFullResponsesStream()

Stream all response events including tool preliminary results:

Event Types

The full stream includes these event types:

Event TypeDescription
response.createdResponse object created
response.in_progressGeneration started
response.output_text.deltaText content chunk
response.output_text.doneText content complete
response.reasoning.deltaReasoning content chunk
response.reasoning.doneReasoning complete
response.function_call_arguments.deltaTool call argument chunk
response.function_call_arguments.doneTool call arguments complete
response.completedFull response complete
tool.preliminary_resultProgress from generator tools (intermediate yields)
tool.resultFinal result from tool execution

Tool Call Streaming

getToolCallsStream()

Stream structured tool calls as they complete:

getToolStream()

Stream tool deltas and preliminary results:

Concurrent Consumers

Multiple consumers can read from the same result:

The underlying ReusableReadableStream ensures each consumer receives all events.

Cancellation

Cancel a stream to stop generation:

Streaming with UI Frameworks

React Example

Server-Sent Events (SSE)

Next Steps

  • Working with Items - Understand the items-based streaming paradigm
  • Tools - Create tools and multi-turn streaming with tools