Open
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:
openai-python/src/openai/types/responses/easy_input_message_param.py
Lines 13 to 18 in ed53107
vs
openai-python/src/openai/types/responses/response_output_message.py
Lines 20 to 21 in ed53107
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