Skip to content

feat(provider): add reasoning-file support#13352

Merged
felixarntz merged 17 commits intomainfrom
non-text-reasoning-support
Mar 16, 2026
Merged

feat(provider): add reasoning-file support#13352
felixarntz merged 17 commits intomainfrom
non-text-reasoning-support

Conversation

@felixarntz
Copy link
Copy Markdown
Collaborator

@felixarntz felixarntz commented Mar 11, 2026

Background

See #13321

Summary

  • Adds new type reasoning-file for files that are part of reasoning rather than actual content
    • Part of provider v4 spec
    • Relevant generate result, content part, stream result, and stream parts in ai are expanded accordingly
    • bug fix: simply by introducing reasoning-file (and thus breaking it apart from file), we fix the bug where reasoning files would before be included in top-level files (e.g. in GenerateTextResult or StepResult), which would lead to a duplicate entry in many scenarios
  • updates google language model to use reasoning-file instead of file with provider metadata where applicable
  • updates relevant google examples which were previously based on the provider options workaround

FYI: 9c1c48d shows a glimpse of what supporting this in future 3P code could look like.

Manual Verification

Run the examples modified here.

Specifically, run examples/ai-functions/src/generate-text/google/image-thinking-multi-step.ts against this branch and against main: With main, you'll see that files will include the same image twice (once as part of reasoning, once as the actual output) - this is the bug this PR effectively fixes.

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

N/A

Related Issues

Fixes #13321

@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label ai/ui anything UI related feature New feature or request labels Mar 11, 2026
@felixarntz felixarntz marked this pull request as ready for review March 13, 2026 19:47
providerMetadata?: ProviderMetadata;
}

export function convertFromReasoningOutputs(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that we have to have these helpers to convert reasoning outputs to reasoning parts and vice-versa.

Maybe it's needed indeed, but curious why this differentiation exists? @lgrammel

Looks like ContentPart internally uses ReasoningOutput, GenerateTextResult and StreamTextResult use ReasoningOutput too, but then StepResult uses ReasoningPart 🤔

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an input / output distinction because inputs and outputs can have different shapes (for DX reasons)

in general, for inputs we want to accept a wide range of formats (so users can just pass in what they need without needing to convert themselves)

for outputs, we want to standardize and offer helpers for conversions, so users can use them however they want (without having to convert or worrying about memory)

files are currently the only case where this distinction is prominent

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re the conversion helpers: we could eliminate it on the input side by allowing generatedfile as input (future work)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. But shouldn't StepResult also use ReasoningOutput rather than ReasoningPart then? It contains reasoning output after all, not input. Wondering whether this is technically a bug?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it might be

Comment on lines +2 to +5
'@ai-sdk/provider-utils': patch
'@ai-sdk/provider': patch
'@ai-sdk/google': patch
'@ai-sdk/xai': patch
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if provider / ai needs to be major (breaking change, see below)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gr2m I think you mentioned we still shouldn't use major bumps here because the overall v7 is considered one? Or did I misunderstand that?

{
name: 'reasoning',
type: 'Array<ReasoningPart>',
type: 'Array<ReasoningPart | ReasoningFilePart>',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are breaking changes because they widen the type that needs to be handled by the users.

* The full reasoning that the model has generated in the last step.
*/
readonly reasoning: Array<ReasoningOutput>;
readonly reasoning: Array<ReasoningOutput | ReasoningFileOutput>;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

breaking change; would be good to list in a migration guide so we do not forget

providerMetadata?: ProviderMetadata;
}

export function convertFromReasoningOutputs(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an input / output distinction because inputs and outputs can have different shapes (for DX reasons)

in general, for inputs we want to accept a wide range of formats (so users can just pass in what they need without needing to convert themselves)

for outputs, we want to standardize and offer helpers for conversions, so users can use them however they want (without having to convert or worrying about memory)

files are currently the only case where this distinction is prominent

providerMetadata?: ProviderMetadata;
}

export function convertFromReasoningOutputs(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re the conversion helpers: we could eliminate it on the input side by allowing generatedfile as input (future work)

@@ -0,0 +1,32 @@
import { SharedV3ProviderMetadata } from '../../shared';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate work: v4 models should use v4 provider metadata

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #13482 and d2d2af1

gr2m pushed a commit that referenced this pull request Mar 16, 2026
## Background

The v4 language model spec types were incorrectly importing and using
shared v3 types (`SharedV3ProviderOptions`, `SharedV3ProviderMetadata`,
`SharedV3Headers`, `SharedV3Warning`) instead of their v4 equivalents.
This meant the v4 spec was not self-contained and depended on v3 shared
types.

Initially pointed out by @lgrammel in
#13352 (comment).

## Summary

Updated all v4 language model spec files to import from `shared/v4`
instead of `shared/v3`, using the correct `SharedV4*` types throughout.
@felixarntz felixarntz enabled auto-merge (squash) March 16, 2026 20:11
@felixarntz felixarntz merged commit f7d4f01 into main Mar 16, 2026
20 checks passed
@felixarntz felixarntz deleted the non-text-reasoning-support branch March 16, 2026 20:14
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 16, 2026

🚀 Published in:

Package Version
ai 7.0.0-beta.19
@ai-sdk/alibaba 2.0.0-beta.6
@ai-sdk/amazon-bedrock 5.0.0-beta.7
@ai-sdk/angular 3.0.0-beta.19
@ai-sdk/anthropic 4.0.0-beta.7
@ai-sdk/assemblyai 3.0.0-beta.4
@ai-sdk/azure 4.0.0-beta.8
@ai-sdk/baseten 2.0.0-beta.5
@ai-sdk/black-forest-labs 2.0.0-beta.3
@ai-sdk/bytedance 2.0.0-beta.3
@ai-sdk/cerebras 3.0.0-beta.5
@ai-sdk/cohere 4.0.0-beta.3
@ai-sdk/deepgram 3.0.0-beta.3
@ai-sdk/deepinfra 3.0.0-beta.5
@ai-sdk/deepseek 3.0.0-beta.4
@ai-sdk/devtools 1.0.0-beta.2
@ai-sdk/elevenlabs 3.0.0-beta.3
@ai-sdk/fal 3.0.0-beta.3
@ai-sdk/fireworks 3.0.0-beta.5
@ai-sdk/gateway 4.0.0-beta.12
@ai-sdk/gladia 3.0.0-beta.3
@ai-sdk/google 4.0.0-beta.11
@ai-sdk/google-vertex 5.0.0-beta.15
@ai-sdk/groq 4.0.0-beta.4
@ai-sdk/huggingface 2.0.0-beta.5
@ai-sdk/hume 3.0.0-beta.3
@ai-sdk/klingai 4.0.0-beta.4
@ai-sdk/langchain 3.0.0-beta.19
@ai-sdk/llamaindex 3.0.0-beta.19
@ai-sdk/lmnt 3.0.0-beta.3
@ai-sdk/luma 3.0.0-beta.3
@ai-sdk/mcp 2.0.0-beta.5
@ai-sdk/mistral 4.0.0-beta.3
@ai-sdk/moonshotai 3.0.0-beta.5
@ai-sdk/open-responses 2.0.0-beta.4
@ai-sdk/openai 4.0.0-beta.8
@ai-sdk/openai-compatible 3.0.0-beta.5
@ai-sdk/perplexity 4.0.0-beta.4
@ai-sdk/prodia 2.0.0-beta.4
@ai-sdk/provider 4.0.0-beta.2
@ai-sdk/provider-utils 5.0.0-beta.3
@ai-sdk/react 4.0.0-beta.19
@ai-sdk/replicate 3.0.0-beta.4
@ai-sdk/revai 3.0.0-beta.4
@ai-sdk/rsc 3.0.0-beta.20
@ai-sdk/svelte 5.0.0-beta.19
@ai-sdk/togetherai 3.0.0-beta.5
@ai-sdk/valibot 3.0.0-beta.3
@ai-sdk/vercel 3.0.0-beta.5
@ai-sdk/vue 4.0.0-beta.19
@ai-sdk/xai 4.0.0-beta.11

@gr2m gr2m mentioned this pull request Apr 9, 2026
2 tasks
felixarntz added a commit that referenced this pull request Apr 10, 2026
## Summary

Fixes the changesets for the following v7 major PRs after the fact to
mark them as `major`, for proper referencing in future changelog / docs:
- #13352 
- #13816
- #12880 
- #13553
- #13971
- #14150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label ai/ui anything UI related feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support non-text reasoning parts and consider decoupling reasoning in the spec

2 participants