fix(openai, openai-compatible): only send null content for assistant messages with tool calls#14950
Merged
Merged
Conversation
lgrammel
approved these changes
May 4, 2026
dancer
added a commit
that referenced
this pull request
May 4, 2026
Contributor
|
🚀 Published in:
|
gr2m
pushed a commit
that referenced
this pull request
Jun 5, 2026
…messages with tool calls (#14950) ## background #13744 changed `content: text` to `content: text || null` for assistant messages. this correctly fixed tool-only messages (openai requires `content: null` when `tool_calls` is present), but also broke the case where an assistant message has empty text and no tool calls - openai rejects `content: null` when `tool_calls` is absent with "Invalid value for 'content': expected a string, got null" per the [openai api spec](https://developers.openai.com/api/reference/go/resources/chat/subresources/completions), content is "required unless `tool_calls` or `function_call` is specified" ## summary - only send `null` when `toolCalls.length > 0`, otherwise preserve the text string - add regression tests for both `@ai-sdk/openai` and `@ai-sdk/openai-compatible` ## verification verified against live openai chat completions api with `openai.chat('gpt-4o-mini')` - empty assistant content now sends `content: ""` and returns a valid response ## related issues follow-up to #13744
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
background
#13744 changed
content: texttocontent: text || nullfor assistant messages. this correctly fixed tool-only messages (openai requirescontent: nullwhentool_callsis present), but also broke the case where an assistant message has empty text and no tool calls - openai rejectscontent: nullwhentool_callsis absent with "Invalid value for 'content': expected a string, got null"per the openai api spec, content is "required unless
tool_callsorfunction_callis specified"summary
nullwhentoolCalls.length > 0, otherwise preserve the text string@ai-sdk/openaiand@ai-sdk/openai-compatibleverification
verified against live openai chat completions api with
openai.chat('gpt-4o-mini')- empty assistant content now sendscontent: ""and returns a valid responserelated issues
follow-up to #13744