-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Context
OpenAI requires both reasoning parts and tool call parts when sending messages to it's responses API.
When you strip reasoning parts then request fails with error:
Item 'fc_06124fefef59a7bc006939630d68f08196875270e343d65c39' of type 'function_call' was provided without its required 'reasoning' item: 'rs_06124fefef59a7bc0069396307aba48196a895e6104fb0d7da'.
In the other hand when you strip tool call parts but leave reasoning it fails with error:
Item 'rs_06124fefef59a7bc006939624618b88196918727e605c4cfdf' of type 'reasoning' was provided without its required following item.
Related code
pruneMessages works in a way that it just removes reasoning parts or tool call parts from message content. Related pruneMessages implementation:
if (reasoning === 'all' || reasoning === 'before-last-message') {
messages = messages.map((message, messageIndex) => {
if (
message.role !== 'assistant' ||
typeof message.content === 'string' ||
(reasoning === 'before-last-message' &&
messageIndex === messages.length - 1)
) {
return message;
}
return {
...message,
content: message.content.filter(part => part.type !== 'reasoning'),
};
});
}
Reproducing step
streamText({
model: openai('gpt-5.1')
providerOptions: {
openai: {
reasoningEffort: 'medium',
}
},
prepareStep: async ({ steps, messages }) => {
const prunedMessages = pruneMessages({
messages,
reasoning: 'all',
})
return { messages: prunedMessages }
},
tools: {
someToolThatNeedsToBeCallend
}
})
How to Fix
I think the best would be to remove all the content if there is reasoning for it. But it will break logic of what there is in pruneMessages now.
AI SDK Version
- ai: 5.0.108
- ai-sdk/react: 2.0.109
- ai-sdk/openai: 2.0.80
Code of Conduct
- I agree to follow this project's Code of Conduct