Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Response Stream Event

From Leeroopedia
Revision as of 13:40, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_python_Response_Stream_Event.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains API_Types, Responses_API
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete discriminated union type alias representing all possible streaming events from the Responses API, provided by the openai-python SDK.

Description

ResponseStreamEvent is a TypeAlias defined as an Annotated[Union[...]] of over 40 distinct event types, discriminated on the type field via PropertyInfo(discriminator="type"). This union covers every event that can be emitted during a streaming response, including lifecycle events (created, in_progress, completed, failed, incomplete, queued), content events (text delta/done, audio delta/done, refusal delta/done), reasoning events (reasoning text delta/done, reasoning summary text delta/done, reasoning summary part added/done), tool call events (function call, web search, file search, code interpreter, image generation, MCP, custom tool), and annotation events.

Usage

Import this type when you need a single type annotation that encompasses all possible streaming events, for example when typing a generic event handler function.

Code Reference

Source Location

Signature

ResponseStreamEvent: TypeAlias = Annotated[
    Union[
        ResponseAudioDeltaEvent,
        ResponseAudioDoneEvent,
        ResponseAudioTranscriptDeltaEvent,
        ResponseAudioTranscriptDoneEvent,
        ResponseCodeInterpreterCallCodeDeltaEvent,
        ResponseCodeInterpreterCallCodeDoneEvent,
        ResponseCodeInterpreterCallCompletedEvent,
        ResponseCodeInterpreterCallInProgressEvent,
        ResponseCodeInterpreterCallInterpretingEvent,
        ResponseCompletedEvent,
        ResponseContentPartAddedEvent,
        ResponseContentPartDoneEvent,
        ResponseCreatedEvent,
        ResponseErrorEvent,
        ResponseFileSearchCallCompletedEvent,
        ResponseFileSearchCallInProgressEvent,
        ResponseFileSearchCallSearchingEvent,
        ResponseFunctionCallArgumentsDeltaEvent,
        ResponseFunctionCallArgumentsDoneEvent,
        ResponseInProgressEvent,
        ResponseFailedEvent,
        ResponseIncompleteEvent,
        ResponseOutputItemAddedEvent,
        ResponseOutputItemDoneEvent,
        ResponseReasoningSummaryPartAddedEvent,
        ResponseReasoningSummaryPartDoneEvent,
        ResponseReasoningSummaryTextDeltaEvent,
        ResponseReasoningSummaryTextDoneEvent,
        ResponseReasoningTextDeltaEvent,
        ResponseReasoningTextDoneEvent,
        ResponseRefusalDeltaEvent,
        ResponseRefusalDoneEvent,
        ResponseTextDeltaEvent,
        ResponseTextDoneEvent,
        ResponseWebSearchCallCompletedEvent,
        ResponseWebSearchCallInProgressEvent,
        ResponseWebSearchCallSearchingEvent,
        ResponseImageGenCallCompletedEvent,
        ResponseImageGenCallGeneratingEvent,
        ResponseImageGenCallInProgressEvent,
        ResponseImageGenCallPartialImageEvent,
        ResponseMcpCallArgumentsDeltaEvent,
        ResponseMcpCallArgumentsDoneEvent,
        ResponseMcpCallCompletedEvent,
        ResponseMcpCallFailedEvent,
        ResponseMcpCallInProgressEvent,
        ResponseMcpListToolsCompletedEvent,
        ResponseMcpListToolsFailedEvent,
        ResponseMcpListToolsInProgressEvent,
        ResponseOutputTextAnnotationAddedEvent,
        ResponseQueuedEvent,
        ResponseCustomToolCallInputDeltaEvent,
        ResponseCustomToolCallInputDoneEvent,
    ],
    PropertyInfo(discriminator="type"),
]

Import

from openai.types.responses import ResponseStreamEvent

I/O Contract

Fields

Name Type Required Description
(discriminator) type field on each variant Yes Each union member has a unique literal type value used for discrimination.

Event Categories

Category Event Types
Lifecycle ResponseCreatedEvent, ResponseInProgressEvent, ResponseCompletedEvent, ResponseFailedEvent, ResponseIncompleteEvent, ResponseQueuedEvent, ResponseErrorEvent
Text Output ResponseTextDeltaEvent, ResponseTextDoneEvent, ResponseRefusalDeltaEvent, ResponseRefusalDoneEvent
Audio Output ResponseAudioDeltaEvent, ResponseAudioDoneEvent, ResponseAudioTranscriptDeltaEvent, ResponseAudioTranscriptDoneEvent
Reasoning ResponseReasoningTextDeltaEvent, ResponseReasoningTextDoneEvent, ResponseReasoningSummaryTextDeltaEvent, ResponseReasoningSummaryTextDoneEvent, ResponseReasoningSummaryPartAddedEvent, ResponseReasoningSummaryPartDoneEvent
Content Parts ResponseContentPartAddedEvent, ResponseContentPartDoneEvent, ResponseOutputItemAddedEvent, ResponseOutputItemDoneEvent
Tool Calls ResponseFunctionCallArgumentsDeltaEvent, ResponseFunctionCallArgumentsDoneEvent, ResponseWebSearchCall*, ResponseFileSearchCall*, ResponseCodeInterpreterCall*, ResponseImageGenCall*, ResponseMcpCall*, ResponseCustomToolCallInput*
Annotations ResponseOutputTextAnnotationAddedEvent

Usage Examples

from openai.types.responses import ResponseStreamEvent
import openai

client = openai.OpenAI()

stream = client.responses.create(
    model="gpt-4o",
    input="Hello, world!",
    stream=True,
)

def handle_event(event: ResponseStreamEvent) -> None:
    if event.type == "response.output_text.delta":
        print(event.delta, end="", flush=True)
    elif event.type == "response.completed":
        print("\nResponse complete.")

for event in stream:
    handle_event(event)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment