Skip to content

Output response types are not usable as parameters #2323

Open
@colinmarc

Description

@colinmarc

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Consider the following code:

messages: ResponseInputParam = [{"role": "developer", "content": instructions}]

# ...
resp = client.responses.create(
    model="o4-mini",
    input=messages,
)

for item in resp.output:
    match item:
        case ResponseOutputMessage(content=content):
            print(item.content)
            messages.append(item)

This seems like it should work fine, but it generates a type checking error:

error: Argument of type "ResponseOutputMessage" cannot be assigned to parameter "object" of type "ResponseInputItemParam" in function "append"
    Type "ResponseOutputMessage" is not assignable to type "ResponseInputItemParam"
      "ResponseOutputMessage" is not assignable to "EasyInputMessageParam"
      "ResponseOutputMessage" is not assignable to "Message"
      "ResponseOutputMessage" is not assignable to "ResponseOutputMessageParam"
      "ResponseOutputMessage" is not assignable to "ResponseFileSearchToolCallParam"
      "ResponseOutputMessage" is not assignable to "ResponseComputerToolCallParam"
      "ResponseOutputMessage" is not assignable to "ComputerCallOutput"
      "ResponseOutputMessage" is not assignable to "ResponseFunctionWebSearchParam"
    ... (reportArgumentType)

I think this is because the parameter types use Required, but the output types don't. For example, EasyMessageInputParam requires content, but ResponseOutputMessage doesn't:

class EasyInputMessageParam(TypedDict, total=False):
content: Required[Union[str, ResponseInputMessageContentListParam]]
"""
Text, image, or audio input to the model, used to generate a response. Can also
contain previous assistant responses.
"""

vs

content: List[Content]
"""The content of the output message."""

I recognize that the bindings are auto-generated and this may not be trivial to fix.

To Reproduce

n/a

Code snippets

OS

linux

Python version

Python v3.13.2

Library version

openai v1.75.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions