Skip to content

Conversation

@ihower
Copy link
Contributor

@ihower ihower commented Dec 26, 2025

Resolved: #2237

This PR ensures that assistant messages with tool calls include an explicit content key with the value None when using the Chat Completions API.

Background

When using the Chat Completions API, assistant messages that contain tool calls are currently sent back to the server without a content key.

Current behavior:

{
  "role": "assistant",
  "tool_calls": [...]
}

Expected behavior:

{
  "role": "assistant",
  "content": null,
  "tool_calls": [...]
}

Why keep the content key even when it is None?

In the Chat Completions API, assistant messages that trigger function or tool calls include "content": null.
(i.e., the returned message did contain the content field, even when it is null).

When sending messages back to the server, this structure should stay the same.

This is also shown in official examples. For example, in the OpenAI Cookbook:

https://github.com/openai/openai-cookbook/blob/bceb1173eb4b8ffb620279dd36c1e2942860f89a/examples/How_to_call_functions_with_chat_models.ipynb

messages.append(chat_response.choices[0].message.to_dict())

This sends the full assistant message, including "content": None, back to the Chat Completions API.

Currently, the SDK drops the content key during the conversion from Responses API items to Chat Completions messages.
This PR adds it back.

If an assistant message has a non-None content value, this change does not overwrite or modify it. The content key is only added when it is missing.

Impact

  • No behavior change for OpenAI’s official API. This actually better matches the behavior of the Chat Completions API and how the openai-python library is used in practice.
  • Improves compatibility with third-party Chat Completions servers that use stricter message validation.

@seratch seratch merged commit 007a65c into openai:main Dec 27, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wireshark packet capture comparison, I personally determined that it was due to missing fields abount run the sdk failed.

2 participants