openai / openai/openai-python

Output response types are not usable as parameters

Open
#2,323 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug sdk
Dominant language
Python
Stars
31.6k
Forks
5.7k
Avg merge
1d 6h
Merged PRs (30d)
96

Description

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:

https://github.com/openai/openai-python/blob/ed53107e10e6c86754866b48f8bd862659134ca8/src/openai/types/responses/easy_input_message_param.py#L13-L18

vs

https://github.com/openai/openai-python/blob/ed53107e10e6c86754866b48f8bd862659134ca8/src/openai/types/responses/response_output_message.py#L20-L21

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing src/openai/types/responses/easy_input_message_param.py and src/openai/types/responses/response_output_message.py, focusing on the required fields described in the report. Trace how these auto-generated types are produced before deciding where the compatibility change belongs. Done means the reported messages.append(item) pattern passes Python type checking without weakening the intended response and input type requirements.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.