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 Output Item Type

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

Overview

Discriminated union type alias and supporting models for representing all possible response output items provided by the openai-python SDK.

Description

ResponseOutputItem is a TypeAlias representing a discriminated union of all possible output item types that can appear in the output array of a Responses API response. It is discriminated on the type field using PropertyInfo(discriminator="type"). Unlike ResponseItem (which includes both input and output items), ResponseOutputItem is scoped to output-only items: output messages, tool calls, reasoning items, compaction items, image generation calls, local shell calls, MCP-related items, and custom tool calls.

The module also defines several supporting Pydantic models:

  • ImageGenerationCall - An image generation request with id, result, status, and type fields.
  • LocalShellCallAction - Describes a shell command to execute with command, env, timeout, user, and working directory.
  • LocalShellCall - A tool call to run a command on the local shell.
  • McpCall - An invocation of a tool on an MCP server.
  • McpListToolsTool - A tool available on an MCP server.
  • McpListTools - A list of tools available on an MCP server.
  • McpApprovalRequest - A request for human approval of a tool invocation.

Usage

Import ResponseOutputItem when you need a type annotation covering all possible output items from a response. Import individual supporting classes when working with specific output item types.

Code Reference

Source Location

Signature

ResponseOutputItem: TypeAlias = Annotated[
    Union[
        ResponseOutputMessage,
        ResponseFileSearchToolCall,
        ResponseFunctionToolCall,
        ResponseFunctionWebSearch,
        ResponseComputerToolCall,
        ResponseReasoningItem,
        ResponseCompactionItem,
        ImageGenerationCall,
        ResponseCodeInterpreterToolCall,
        LocalShellCall,
        ResponseFunctionShellToolCall,
        ResponseFunctionShellToolCallOutput,
        ResponseApplyPatchToolCall,
        ResponseApplyPatchToolCallOutput,
        McpCall,
        McpListTools,
        McpApprovalRequest,
        ResponseCustomToolCall,
    ],
    PropertyInfo(discriminator="type"),
]

Import

from openai.types.responses import ResponseOutputItem

I/O Contract

Union Members

Type Discriminator Value Description
ResponseOutputMessage "message" An output message from the model.
ResponseFileSearchToolCall "file_search_call" A file search tool call.
ResponseFunctionToolCall "function_call" A function tool call.
ResponseFunctionWebSearch "web_search_call" A web search tool call.
ResponseComputerToolCall "computer_call" A computer use tool call.
ResponseReasoningItem "reasoning" A reasoning item from the model.
ResponseCompactionItem "compaction" A compaction item.
ImageGenerationCall "image_generation_call" An image generation request.
ResponseCodeInterpreterToolCall "code_interpreter_call" A code interpreter tool call.
LocalShellCall "local_shell_call" A local shell command call.
ResponseFunctionShellToolCall "function_shell_call" A function shell tool call.
ResponseFunctionShellToolCallOutput "function_shell_call_output" Output from a function shell tool call.
ResponseApplyPatchToolCall "apply_patch_call" An apply patch tool call.
ResponseApplyPatchToolCallOutput "apply_patch_call_output" Output from an apply patch tool call.
McpCall "mcp_call" An MCP tool call invocation.
McpListTools "mcp_list_tools" A list of tools from an MCP server.
McpApprovalRequest "mcp_approval_request" An MCP approval request.
ResponseCustomToolCall "custom_tool_call" A custom tool call.

Usage Examples

import openai

client = openai.OpenAI()

response = client.responses.create(
    model="gpt-4o",
    input="Explain quantum computing briefly.",
)

for item in response.output:
    # item is typed as ResponseOutputItem (discriminated union)
    if item.type == "message":
        for content in item.content:
            if content.type == "output_text":
                print(content.text)
    elif item.type == "reasoning":
        print(f"Reasoning item: {item.id}")
    elif item.type == "function_call":
        print(f"Function call: {item.name}({item.arguments})")
    elif item.type == "mcp_call":
        print(f"MCP call: {item.name} on {item.server_label}")

Related Pages

Page Connections

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