type 'reasoning' was provided without its required following item
Description
Related to #7099 but now with gpt-5
The provided context was:
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "",
"providerOptions": {
"openai": {
"itemId": "rs_689cfc25afbc8194836745e69eff008a04baf2d6100d1d70",
"reasoningEncryptedContent": null
}
}
},
...
I can't recreate this consistently, it seems it depends when openai wants to provide that reasoning context back, and it seems the package is failing to serialize it
Additionally, I do not have it set to include the encrypted reasoning content:
openai: {
reasoningEffort: "minimal",
} satisfies OpenAIResponsesProviderOptions,
AI SDK Version
"@ai-sdk/openai": "^2.0.5", "ai": "^5.0.9",
actually i'm suspecting it might be because the text is blank? the provider options seems to not care about what's inside.
I haven't hit it again since updating to 2.0.12, but if there wasn't a specific patch for it, I wouldn't dare assume it's not an issue anymore
I'm also seeing the same issue even after updating to the latest version
I'm getting this error when reasoning is false but the max output token limit is exceeded without adding a custom error. It looks like it happens if no text is returned for one message, then a second message is attempted (not a retry).
some more info on OpenAI community forum https://community.openai.com/t/how-to-solve-gpt-5-reasoning-error-without-previous-response-id/1344988/2
Another issue about this https://github.com/vercel/ai/issues/7099 (closed)
EDIT:
I manage to make it work with these versions:
"dependencies": {
- "@ai-sdk/openai": "^2.0.12",
+ "@ai-sdk/openai": "^2.0.15",
- "ai": "5.0.0-beta.6",
+ "ai": "5.0.15",
$ pnpm list |grep 'ai\|openai'
[email protected] ...
@ai-sdk/openai 2.0.15
@ai-sdk/provider 2.0.0-beta.1
@ai-sdk/react 2.0.0-beta.6
ai 5.0.15
And if you're using the ai-chatbot Repo, you'll need this PR / patch otherwise the webapp will not build.
And if you're getting this type error, upgrade @ai-sdk/react to 2.0.15
Error in ./components/artifact-messages.tsx:13
Failed to compile.
./components/artifact-messages.tsx:13:26
Type error: Type 'ChatMessage' does not satisfy the constraint 'UIMessage<unknown, UIDataTypes, UITools>'.
Types of property 'parts' are incompatible.
Type 'UIMessagePart<CustomUIDataTypes, ChatTools>[]' is not assignable to type 'UIMessagePart<UIDataTypes, UITools>[]'.
Type 'UIMessagePart<CustomUIDataTypes, ChatTools>' is not assignable to type 'UIMessagePart<UIDataTypes, UITools>'.
Type '{ type: "dynamic-tool"; toolName: string; toolCallId: string; } & { state: "input-streaming"; input: unknown; output?: undefined; errorText?: undefined; }' is not assignable to type 'UIMessagePart<UIDataTypes, UITools>'.
Type '{ type: "dynamic-tool"; toolName: string; toolCallId: string; } & { state: "input-streaming"; input: unknown; output?: undefined; errorText?: undefined; }' is not assignable to type '{ type: `tool-${string}`; toolCallId: string; } & { state: "input-streaming"; input: unknown; providerExecuted?: boolean | undefined; }'.
Type '{ type: "dynamic-tool"; toolName: string; toolCallId: string; } & { state: "input-streaming"; input: unknown; output?: undefined; errorText?: undefined; }' is not assignable to type '{ type: `tool-${string}`; toolCallId: string; }'.
Types of property 'type' are incompatible.
Type '"dynamic-tool"' is not assignable to type '`tool-${string}`'.
11 | interface ArtifactMessagesProps {
12 | chatId: string;
> 13 | status: UseChatHelpers<ChatMessage>['status'];
| ^
My package.json is now
--- i/package.json
+++ w/package.json
@@ -20,8 +20,8 @@
},
"dependencies": {
"@ai-sdk/openai": "^2.0.15",
- "@ai-sdk/provider": "2.0.0-beta.1",
- "@ai-sdk/react": "2.0.0-beta.6",
+ "@ai-sdk/provider": "2.0.0",
+ "@ai-sdk/react": "2.0.15",
"@ai-sdk/xai": "2.0.0-beta.2",
...
"ai": "5.0.15",
$ pnpm list |grep 'ai\|openai'
[email protected]
@ai-sdk/openai 2.0.15
@ai-sdk/provider 2.0.0
@ai-sdk/react 2.0.15
@ai-sdk/xai 2.0.0-beta.2
ai 5.0.15
I am seeing this still as of
"ai": "5.0.15"
"@ai-sdk/openai": "2.0.15"
I am also facing similar issue but surprisingly only when the agent calls the web search tool (using openai web_search tool). In other tool calls it works fine.
I have also tried removing reasoning option but still facing the issue.
Using gpt-5-mini
My package.json -
"@ai-sdk/openai": "^2.0.16", "@ai-sdk/react": "^2.0.16", "ai": "^5.0.16",
@anish2110 i have tested reasoning and the websearch tool in combination with gpt-5 over multiple steps and could not reproduce the issue.
if someone could share a script or a server route that reproduces the issue that would be very helpful
@lgrammel you can use the content from my initial message to construct a call that throws the error every time:
const model = openai("gpt-5-2025-08-07")
const result = await generateText({
model,
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "hello" },
{
role: "assistant",
content: [
{
type: "reasoning",
text: "", // this still fails with text content
providerOptions: {
openai: {
itemId: "rs_689cfc25afbc8194836745e69eff008a04baf2d6100d1d70",
reasoningEncryptedContent: null,
},
},
},
{
type: "text",
text: "I am thinking...",
},
],
},
{ role: "user", content: "hello" },
],
})
AI_APICallError: Item 'rs_689cfc25afbc8194836745e69eff008a04baf2d6100d1d70' of type 'reasoning' was provided without its required following item.
@danthegoodman1 what you have is invalid because the following text does not have openai provider metadata. of course it will fail. the question is how do you get that response?
That I don't know exactly, but that was a contrived example so maybe I didn't construct it right, but it is the same error so I'd expect that's what's happening.
It's going to be really hard to get that to be a determinsitic response, but the ai sdk/openai provider in some way is returning invalid message parts.
Unfortunately this is also making gpt-5 unsuable, because we can't predict when it will corrupt the context.
The OpenAI responses model always sends out the id in the text-start chunk: https://github.com/vercel/ai/blob/main/packages/openai/src/responses/openai-responses-language-model.ts#L737
The only time this won't happen is when OpenAI does not send it which is extremely unlikely.
However, there was a related bug that has been fixed: https://github.com/vercel/ai/pull/7968 (fixed in 5.0.10).
Has this happened on chats that were created after you started using 5.0.10?
It appears from other messages above that folks are running into it with much later versions (5.0.15/16)
@lgrammel I am experiencing this with version 5.0.30([email protected])
here's part of my stack trace in case it's useful:
node:internal/process/promises:394
triggerUncaughtException(err, true /* fromPromise */);
^
APICallError [AI_APICallError]: Item 'rs_...' of type 'reasoning' was provided without its required following item.
at <anonymous> (/Users/zsiegel/.../node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/response-handler.ts:56:16)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async postToApi (/Users/zsiegel/.../node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:112:28)
at async OpenAIResponsesLanguageModel.doGenerate (/Users/zsiegel/.../node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/openai/src/responses/openai-responses-language-model.ts:326:9)
at async fn (/Users/zsiegel/.../node_modules/.pnpm/[email protected][email protected]/node_modules/ai/src/generate-text/generate-text.ts:382:32)
at async <anonymous> (/Users/zsiegel/.../node_modules/.pnpm/[email protected][email protected]/node_modules/ai/src/telemetry/record-span.ts:18:22)
at async _retryWithExponentialBackoff (/Users/zsiegel/.../node_modules/.pnpm/[email protected][email protected]/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:12)
at async fn (/Users/zsiegel/.../node_modules/.pnpm/[email protected][email protected]/node_modules/ai/src/generate-text/generate-text.ts:338:34)
at async <anonymous> (/Users/zsiegel/.../node_modules/.pnpm/[email protected][email protected]/node_modules/ai/src/telemetry/record-span.ts:18:22)
at async generateText (/Users/zsiegel/.../node_modules/.pnpm/[email protected][email protected]/node_modules/ai/src/generate-text/generate-text.ts:274:12) {
cause: undefined,
url: 'https://api.openai.com/v1/responses',
requestBodyValues: {
model: 'gpt-5-codex',
input: [
{
role: 'developer',
...
responseBody: '{\n' +
' "error": {\n' +
` "message": "Item '...' of type 'reasoning' was provided without its required following item.",\n` +
' "type": "invalid_request_error",\n' +
' "param": "input",\n' +
' "code": null\n' +
' }\n' +
'}',
isRetryable: false,
data: {
error: {
message: "Item 'rs_...' of type 'reasoning' was provided without its required following item.",
type: 'invalid_request_error',
param: 'input',
code: null
}
},
[Symbol(vercel.ai.error)]: true,
[Symbol(vercel.ai.error.AI_APICallError)]: true
I got the same issue as well. Here's a small investigation done by my IDE.
AI SDK OpenAI Provider - Persistent Reasoning Artifacts Bug
Summary
When using the AI SDK's OpenAI provider with reasoningEffort enabled (e.g., medium), the provider appears to persist reasoning artifacts (rs_* items) in a way that causes subsequent API calls to fail with a 400 Bad Request error from OpenAI's Responses API.
Error Message:
LLMRequestError: Item 'rs_...' of type 'reasoning' was provided without its required following item.
Investigation Findings
1. Clean Input Messages: We verified via deep debug logging that the messages array passed to streamText is "clean" - it contains only text and tool-call parts. No reasoning parts are present in the input.
Log Trace (Input to streamText):
[
{
"role": "assistant",
"content": [
{ "type": "text", "text": "" },
{ "type": "tool-call", "toolCallId": "call_...", "toolName": "...", "input": {} }
]
},
{
"role": "tool",
"content": [
{ "type": "tool-result", "toolCallId": "call_...", "toolName": "...", "result": "..." }
]
}
]
2. Persistence of Hidden State: Despite the clean input, the OpenAI API rejects the request citing a specific reasoning item ID (rs_...) that was generated in the previous turn. This suggests that the AI SDK or the OpenAI provider is maintaining state (perhaps via previous_response_id or similar mechanism) that links the new request to the previous reasoning steps, even when messages are stateless.
3. Reasoning Summary: We explicitly removed reasoningSummary from the provider options, but the issue persists.
Hypothesis
The AI SDK's OpenAI provider, when detecting reasoningEffort, might be:
Automatically using the Responses API's stateful features (e.g., previous_response_id) without explicit opt-in. Or, streamText is somehow retaining context from the previous turn if the same model instance is reused (though we create a new instance each time).
Reproduction Steps
Setup:
AI SDK with OpenAI provider (currently using [email protected], @ai-sdk/[email protected]) Model enabled for reasoning (e.g., o1 or compatible). reasoningEffort: "medium".
Scenario:
Turn 1: User asks a question that triggers a tool call. Turn 1 Response: Model reasons (generating rs_... items internally) and calls a tool. Turn 2: Tool result is fed back to the model. Turn 2 Request: We send the history (User -> Assistant [Tool Call] -> Tool [Result]). Result: 400 Bad Request: "Item 'rs_...' of type 'reasoning' was provided without its required following item." Logs for Reference Clean Input (verified):
[DEBUG] Sending messages to AI SDK: [
{
"role": "assistant",
"content": [
{ "type": "text", "text": "" },
{ "type": "tool-call", "toolCallId": "call_tjFuhKhDUrrDlJFwVEM3wrdc", ... }
]
},
{
"role": "tool",
"content": [
{ "type": "tool-result", "toolCallId": "call_tjFuhKhDUrrDlJFwVEM3wrdc", ... }
]
}
]
Error:
[ERROR] LLM Error: LLMRequestError - Item 'rs_0a1dc6172fd02e9d006922c262186881a2ab262138141fcf92' of type 'reasoning' was provided without its required following item.
@lvndry I'm facing the same issue. Could you tell me if you have found a workaround? Thanks!
https://github.com/vercel/ai/issues/7099#issuecomment-3567630392
Identify issue type
Identified as Bug
Confidence: High
Rationale
This describes a concrete, recurring failure in existing GPT-5/OpenAI Responses behavior, where conversation context involving reasoning or tool calls becomes invalid and subsequent requests throw an API error.
Evidence
- The OpenAI provider produces requests rejected with a 400 error: reasoning items are sent without their required following item.
- Multiple users report the failure on later AI SDK/OpenAI provider versions, including ai 5.0.47 and @ai-sdk/openai 2.0.32.
- A reporter observed the error after a reasoning-enabled tool call even though the subsequent input messages contained no reasoning parts.
- The maintainer identified a related serialization bug fixed in 5.0.10, but later comments indicate the failure persists.