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 Responses Types Init

From Leeroopedia
Knowledge Sources
Domains API_Types, Python
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete module for public re-export of all response-related types provided by the openai-python SDK.

Description

The responses/__init__.py module serves as the central namespace for the entire responses type system in the openai-python SDK. It consolidates over 200 type re-exports from individual submodules into a single, convenient import surface. Every type defined across the openai.types.responses package is re-exported here using the from .module import Name as Name pattern, which makes each symbol part of the public API and visible to static type checkers.

The re-exported types span several categories:

  • Core response types: Response, ResponseStatus, ResponseUsage, ResponseError, ResponseItem, ResponseItemList
  • Tool definitions: Tool, ToolParam, FunctionTool, ComputerTool, WebSearchTool, FileSearchTool, ApplyPatchTool
  • Input/output types: ResponseInputItem, ResponseInputParam, ResponseOutputItem, ResponseOutputMessage, ResponseOutputText
  • Streaming event types: ResponseStreamEvent, ResponseTextDeltaEvent, ResponseAudioDeltaEvent, ResponseContentPartAddedEvent, and many more
  • Parsed response types: ParsedResponse, ParsedContent, ParsedResponseOutputItem
  • Parameter types (TypedDicts): ResponseCreateParams, ResponseInputItemParam, ToolParam, etc.
  • Container and network policy types: ContainerAuto, ContainerReference, ContainerNetworkPolicyDisabled, ContainerNetworkPolicyAllowlist

This file is auto-generated from the OpenAI API spec by the Stainless code generation toolchain.

Usage

Use this module whenever you need to import response-related types for type annotations, runtime isinstance checks, or constructing request parameters. Importing from openai.types.responses is the recommended approach rather than importing from individual submodules.

Code Reference

Source Location

Signature

# Re-export pattern (representative sample from 200+ re-exports):
from .tool import Tool as Tool
from .response import Response as Response
from .tool_param import ToolParam as ToolParam
from .response_input_item import ResponseInputItem as ResponseInputItem
from .response_input_param import ResponseInputParam as ResponseInputParam
from .response_output_item import ResponseOutputItem as ResponseOutputItem
from .response_create_params import ResponseCreateParams as ResponseCreateParams
from .response_stream_event import ResponseStreamEvent as ResponseStreamEvent
from .parsed_response import (
    ParsedContent as ParsedContent,
    ParsedResponse as ParsedResponse,
    ParsedResponseOutputItem as ParsedResponseOutputItem,
    ParsedResponseOutputText as ParsedResponseOutputText,
    ParsedResponseOutputMessage as ParsedResponseOutputMessage,
    ParsedResponseFunctionToolCall as ParsedResponseFunctionToolCall,
)

Import

from openai.types.responses import (
    Response,
    Tool,
    ToolParam,
    ResponseInputItem,
    ResponseInputParam,
    ResponseOutputItem,
    ResponseCreateParams,
    ResponseStreamEvent,
    ParsedResponse,
)

I/O Contract

Inputs

Name Type Required Description
N/A N/A N/A This is a re-export module with no callable interface. It provides type symbols for import only.

Outputs

Name Type Description
Tool TypeAlias Union of all tool definition Pydantic models (FunctionTool, WebSearchTool, Mcp, CodeInterpreter, etc.)
Response BaseModel The main response object returned by the Responses API
ResponseInputItem TypeAlias Union of all valid input item types for response creation
ResponseInputParam TypeAlias List of ResponseInputItemParam TypedDicts for request parameters
ResponseCreateParams Union Union of ResponseCreateParamsNonStreaming and ResponseCreateParamsStreaming
ResponseStreamEvent TypeAlias Union of all server-sent event types during streaming
ParsedResponse BaseModel A response with structured/parsed output content

Usage Examples

Basic Usage

from openai.types.responses import Response, Tool, ResponseCreateParams

# Use Response for type annotations
def process_response(resp: Response) -> str:
    return resp.id

# Use Tool for type-checking tool definitions
def describe_tool(tool: Tool) -> str:
    return tool.type

Importing Streaming Event Types

from openai.types.responses import (
    ResponseStreamEvent,
    ResponseTextDeltaEvent,
    ResponseCompletedEvent,
    ResponseCreatedEvent,
)

def handle_event(event: ResponseStreamEvent) -> None:
    if isinstance(event, ResponseTextDeltaEvent):
        print(event.delta)
    elif isinstance(event, ResponseCompletedEvent):
        print("Done!")

Importing Parameter Types

from openai.types.responses import (
    ResponseInputItemParam,
    ResponseInputParam,
    ToolParam,
)

# Build typed input for the Responses API
input_items: ResponseInputParam = [
    {
        "role": "user",
        "content": [{"type": "input_text", "text": "Hello!"}],
        "type": "message",
    }
]

Related Pages

Page Connections

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