Skip to content

[v6.0] fix(provider/xai): extract reasoning text from content in responses doGenerate#16798

Merged
gr2m merged 1 commit into
release-v6.0from
backport-v6.0/fix-13372
Jul 6, 2026
Merged

[v6.0] fix(provider/xai): extract reasoning text from content in responses doGenerate#16798
gr2m merged 1 commit into
release-v6.0from
backport-v6.0/fix-13372

Conversation

@gr2m

@gr2m gr2m commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Backport of #13372 to the release-v6.0 branch. xAI's non-streaming responses API returns reasoning text in the content field on reasoning output items (as reasoning_text parts), not only in summary, so reasoning was silently dropped in generateText. This ports the fix: the reasoning output item schema gains the content field, and doGenerate falls back to reading reasoning text from content when summary is empty. During conflict resolution, v6's existing condition (reasoningText || part.encrypted_content with the hasMetadata providerMetadata spread, which supports encrypted content with empty reasoning text) was kept intact instead of main's older if (reasoningText) structure, and both v6's existing encrypted-content test and the new content-fallback regression test were retained. Part of the v6.0 backport tracking issue #16767.

…oGenerate (#13372)

xAI's non-streaming responses API returns reasoning text in the
`content` field on reasoning output items (as `reasoning_text` parts),
not in the `summary` field. the SDK only read from `summary`, so
reasoning was silently dropped in `generateText` - streaming worked fine
since it uses `reasoning_summary_text.delta` events

- add `content` field to the reasoning output item schema in
`xai-responses-api.ts`
- read reasoning text from `content` when `summary` is empty in
doGenerate
- add test for the content fallback path
- add generate-text reasoning example

<details>
<summary>before: no reasoning shown</summary>

```
$ pnpm tsx src/generate-text/xai/responses-reasoning.ts
--- text ---
The word "strawberry" contains **3** instances of the letter "r".
```

</details>

<details>
<summary>after: reasoning properly extracted</summary>

```
$ pnpm tsx src/generate-text/xai/responses-reasoning.ts
--- reasoning ---
First, the user asked: "How many 'r's are in the word 'strawberry'?"

I need to count the number of times the letter 'r' appears in the word "strawberry".

Let me spell out the word: S-T-R-A-W-B-E-R-R-Y.

Now, let's go through each letter:

1. S - Not an 'r'
2. T - Not an 'r'
3. R - This is an 'r' (first one)
4. A - Not an 'r'
5. W - Not an 'r'
6. B - Not an 'r'
7. E - Not an 'r'
8. R - This is an 'r' (second one)
9. R - This is an 'r' (third one)
10. Y - Not an 'r'

So, the 'r's are at positions 3, 8, and 9.
That means there are 3 'r's in "strawberry".

--- text ---
The word "strawberry" contains **3** instances of the letter "r".
```

</details>

- [x] tests have been added / updated (for bug fixes / features)
- [ ] documentation has been added / updated (for bug fixes / features)
- [x] a _patch_ changeset for relevant packages has been added (run
`pnpm changeset` in root)
- [x] i have reviewed this pull request (self-review)

---------

Co-authored-by: Felix Arntz <felix.arntz@vercel.com>
(cherry picked from commit 12115e9)
@gr2m gr2m added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Jul 6, 2026
@gr2m gr2m merged commit 19eece6 into release-v6.0 Jul 6, 2026
52 checks passed
@gr2m gr2m deleted the backport-v6.0/fix-13372 branch July 6, 2026 20:06
github-actions Bot added a commit that referenced this pull request Jul 6, 2026
@github-actions github-actions Bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Backport to release-v5.0 created but has conflicts: #16827

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 6.0.221 github npm
@ai-sdk/alibaba 1.0.36 github npm
@ai-sdk/amazon-bedrock 4.0.131 github npm
@ai-sdk/angular 2.0.222 github npm
@ai-sdk/anthropic 3.0.95 github npm
@ai-sdk/anthropic-aws 1.0.17 github npm
@ai-sdk/assemblyai 2.0.44 github npm
@ai-sdk/azure 3.0.86 github npm
@ai-sdk/baseten 1.0.61 github npm
@ai-sdk/black-forest-labs 1.0.45 github npm
@ai-sdk/bytedance 1.0.25 github npm
@ai-sdk/cerebras 2.0.64 github npm
@ai-sdk/cohere 3.0.46 github npm
@ai-sdk/deepgram 2.0.43 github npm
@ai-sdk/deepinfra 2.0.62 github npm
@ai-sdk/deepseek 2.0.46 github npm
@ai-sdk/elevenlabs 2.0.43 github npm
@ai-sdk/fal 2.0.44 github npm
@ai-sdk/fireworks 2.0.66 github npm
@ai-sdk/gateway 3.0.145 github npm
@ai-sdk/gladia 2.0.43 github npm
@ai-sdk/google 3.0.90 github npm
@ai-sdk/google-vertex 4.0.158 github npm
@ai-sdk/groq 3.0.49 github npm
@ai-sdk/huggingface 1.0.60 github npm
@ai-sdk/hume 2.0.43 github npm
@ai-sdk/klingai 3.0.28 github npm
@ai-sdk/langchain 2.0.229 github npm
@ai-sdk/llamaindex 2.0.221 github npm
@ai-sdk/lmnt 2.0.43 github npm
@ai-sdk/luma 2.0.43 github npm
@ai-sdk/mcp 1.0.60 github npm
@ai-sdk/mistral 3.0.47 github npm
@ai-sdk/moonshotai 2.0.34 github npm
@ai-sdk/open-responses 1.0.26 github npm
@ai-sdk/openai 3.0.82 github npm
@ai-sdk/openai-compatible 2.0.58 github npm
@ai-sdk/perplexity 3.0.44 github npm
@ai-sdk/prodia 1.0.42 github npm
@ai-sdk/provider-utils 4.0.37 github npm
@ai-sdk/quiverai 1.0.10 github npm
@ai-sdk/react 3.0.223 github npm
@ai-sdk/replicate 2.0.43 github npm
@ai-sdk/revai 2.0.43 github npm
@ai-sdk/rsc 2.0.221 github npm
@ai-sdk/svelte 4.0.221 github npm
@ai-sdk/togetherai 2.0.63 github npm
@ai-sdk/valibot 2.0.38 github npm
@ai-sdk/vercel 2.0.60 github npm
@ai-sdk/voyage 1.0.14 github npm
@ai-sdk/vue 3.0.221 github npm
@ai-sdk/xai 3.0.104 github npm

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.

3 participants