Skip to content

fix(openai, openai-compatible): only send null content for assistant messages with tool calls#14950

Merged
dancer merged 4 commits into
mainfrom
josh/fix-null-content-no-tools
May 4, 2026
Merged

fix(openai, openai-compatible): only send null content for assistant messages with tool calls#14950
dancer merged 4 commits into
mainfrom
josh/fix-null-content-no-tools

Conversation

@dancer

@dancer dancer commented May 4, 2026

Copy link
Copy Markdown
Collaborator

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, 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

dancer added a commit that referenced this pull request May 4, 2026
…or assistant messages with tool calls (#14951)

## background

backport of #14950 from main to release-v6.0

## related issues

backport of #14950
follow-up to #13744
@dancer dancer merged commit cd9c311 into main May 4, 2026
21 checks passed
@dancer dancer deleted the josh/fix-null-content-no-tools branch May 4, 2026 15:37
@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.0-canary.118
@ai-sdk/alibaba 2.0.0-canary.40
@ai-sdk/angular 3.0.0-canary.118
@ai-sdk/azure 4.0.0-canary.46
@ai-sdk/baseten 2.0.0-canary.38
@ai-sdk/cerebras 3.0.0-canary.38
@ai-sdk/cohere 4.0.0-canary.34
@ai-sdk/deepinfra 3.0.0-canary.38
@ai-sdk/fireworks 3.0.0-canary.38
@ai-sdk/google-vertex 5.0.0-canary.68
@ai-sdk/huggingface 2.0.0-canary.38
@ai-sdk/langchain 3.0.0-canary.118
@ai-sdk/llamaindex 3.0.0-canary.118
@ai-sdk/mistral 4.0.0-canary.35
@ai-sdk/moonshotai 3.0.0-canary.38
@ai-sdk/openai 4.0.0-canary.46
@ai-sdk/openai-compatible 3.0.0-canary.38
@ai-sdk/otel 1.0.0-canary.64
@ai-sdk/react 4.0.0-canary.118
@ai-sdk/rsc 3.0.0-canary.119
@ai-sdk/svelte 5.0.0-canary.118
@ai-sdk/togetherai 3.0.0-canary.38
@ai-sdk/vercel 3.0.0-canary.38
@ai-sdk/vue 4.0.0-canary.118
@ai-sdk/workflow 1.0.0-canary.33
@ai-sdk/xai 4.0.0-canary.51

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants