Skip to content

feat(provider): add support for provider references and uploading files as supported per provider#13816

Merged
felixarntz merged 64 commits intomainfrom
fa/provider-independent-id-upload-files
Apr 2, 2026
Merged

feat(provider): add support for provider references and uploading files as supported per provider#13816
felixarntz merged 64 commits intomainfrom
fa/provider-independent-id-upload-files

Conversation

@felixarntz
Copy link
Copy Markdown
Collaborator

Background

The AI SDK supports passing media files inline or via URL, but has no way to upload files directly to a provider or reference previously uploaded files across providers. Some providers return internal file IDs (not URLs) from their upload APIs, and switching providers mid-conversation requires a way to map the same logical file to different provider-specific identifiers.

Summary

Introduces uploadFile as a top-level function and ProviderReference (Record<string, string>) as the provider-independent way to reference uploaded files.

  • New spec types: SharedV4ProviderReference (provider package), FilesV4 interface with uploadFile method, UploadFileResult; mediaType and filename** are top-level parameters as they're widely supported and used
  • New top-level API: uploadFile({ files, data, mediaType?, filename?, providerOptions? }) in the ai package, with auto-detection of media type from file bytes when not provided
  • Provider implementations: files() interface on Anthropic, Google, OpenAI, and xAI providers, each implementing FilesV4.uploadFile
    • Other providers don't support uploading files, or they only support uploading files for batch inference (*.jsonl), which we don't support anyway.
  • Provider reference support in messages: LanguageModelV4FilePart.data now accepts SharedV4ProviderReference in addition to DataContent; providers that support file references (Anthropic, Google, OpenAI, xAI) resolve them via resolveProviderReference; all other providers throw UnsupportedFunctionalityError
  • Spec cleanup: file-id and image-file-id tool result output types replaced with file-reference and image-file-reference using SharedV4ProviderReference instead of string | Record<string, string>
  • Uploading from URL is not supported — no provider supports this, and auto-downloading is questionable; callers should fetch first
  • reasoning-file was not touched — it is model-generated as part of reasoning output, so provider references are not applicable
  • Docs included — Docs about uploadFile and ProviderReference, and a new architecture guide are included

Design decisions

  • ProviderReference is a plain Record<string, string> rather than a wrapper class, keeping it simple to create and merge
  • The isLikelyText heuristic for media type detection and the documentMediaTypeSignatures are kept internal (not exported) — they work well enough for uploadFile but are not general-purpose utilities
  • resolveProviderReference (provider-utils) does the lookup by provider name and throws with a clear error listing available providers when the reference doesn't contain an entry for the current provider

Open questions

  1. Should we include a type property in ProviderReference to distinguish different kinds of provider references (e.g. file vs skill, see Add support for creating and managing remote skills (e.g. Anthropic, OpenAI) via abstraction with new top-level API #12855)?
  2. Should mediaType and filename be top-level fields in the uploadFile result object?
    • They're currently top-level request parameters, but in the response they're in providerMetadata.
  3. mergeProviderReferences is currently inlined in an example (multi-provider.ts) — should we offer this as a utility, or leave it for later?
  4. file-id and image-file-id were removed in toModelOutput return value — should we deprecate them instead and/or offer auto-migration via codemod?
  5. Out of scope: supporting providers that allow uploading files solely for batch inference (e.g. Cohere, Groq, Mistral), which we don't support at a provider level yet anyway - probably leave for later?

Manual Verification

Upload file examples were added for all 4 supported providers (Anthropic, Google, OpenAI, xAI), each with image, PDF, and text variants.

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

Reuse the new ProviderReference approach for #12855.

Related Issues

Fixes #12995

@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 documentation Improvements or additions to documentation feature New feature or request provider/anthropic Issues related to the @ai-sdk/anthropic provider provider/google Issues related to the @ai-sdk/google provider provider/openai Issues related to the @ai-sdk/openai provider provider/xai Issues related to the @ai-sdk/xai provider labels Mar 24, 2026
Copy link
Copy Markdown
Collaborator

@lgrammel lgrammel left a comment

Choose a reason for hiding this comment

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

might be good to update the migration guide as part of this PR so we do not forget about the breaking changes / required migrations

Comment thread packages/provider/src/errors/no-such-provider-reference-error.ts
data,
signatures: [...imageMediaTypeSignatures, ...documentMediaTypeSignatures],
}) ??
(isLikelyText(data) ? 'text/plain' : undefined);
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.

mimeType and mediaType are the same afaik (mime type is the original name, media type is the current standard name), and web standards have moved to mediaType, which is why i standardized everything on mediaType. Re-introducing mimeType would make it inconsistent (and confusing imo if we have both) - if we have mimeType anywhere we should rename it to mediaType (unless it is provider specific).

https://en.wikipedia.org/wiki/Media_type

}
| {
type: 'file-id';
type: 'file-reference';
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.

above we used data: LanguageModelV4DataContent | SharedV4ProviderReference;, here we have separate file-reference/file-data types.

this is somewhat inconsistent. the separation here makes sense to me (bc file reference do not need filename etc) - wondering if it should be changed above

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.

opened #14010

Comment thread packages/provider/src/files/v4/files-v4.ts Outdated
Comment thread packages/provider-utils/src/resolve-provider-reference.ts
Comment on lines +14 to +19
const providerMap = {
anthropic: (modelId: string) => anthropic(modelId),
google: (modelId: string) => google(modelId),
openai: (modelId: string) => openai.responses(modelId),
xai: (modelId: string) => xai(modelId),
};
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.

use provider registry? (or todo for 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.

will do this in a separate PR next week

prompt: standardizedPrompt,
supportedUrls: await model.supportedUrls,
download,
provider: model.provider.split('.')[0],
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.

maybe consider extracting a function so we can search for it when we removed this in the future

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.

since it's temporary, I think it's okay not to introduce an external helper for this.

looking for provider.split('.')[0] throughout the codebase will show all relevant usage

Comment thread packages/ai/src/ui/convert-to-model-messages.ts
Comment thread packages/ai/src/upload-file/upload-file.ts
Comment thread packages/azure/src/azure-openai-provider.ts
@felixarntz felixarntz enabled auto-merge (squash) April 2, 2026 21:25
@felixarntz felixarntz merged commit c29a26f into main Apr 2, 2026
19 checks passed
@felixarntz felixarntz deleted the fa/provider-independent-id-upload-files branch April 2, 2026 21:31
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Apr 2, 2026

🚀 Published in:

Package Version
ai 7.0.0-beta.61
@ai-sdk/alibaba 2.0.0-beta.16
@ai-sdk/amazon-bedrock 5.0.0-beta.21
@ai-sdk/angular 3.0.0-beta.61
@ai-sdk/anthropic 4.0.0-beta.17
@ai-sdk/assemblyai 3.0.0-beta.12
@ai-sdk/azure 4.0.0-beta.21
@ai-sdk/baseten 2.0.0-beta.14
@ai-sdk/black-forest-labs 2.0.0-beta.11
@ai-sdk/bytedance 2.0.0-beta.11
@ai-sdk/cerebras 3.0.0-beta.14
@ai-sdk/cohere 4.0.0-beta.12
@ai-sdk/deepgram 3.0.0-beta.11
@ai-sdk/deepinfra 3.0.0-beta.14
@ai-sdk/deepseek 3.0.0-beta.13
@ai-sdk/devtools 1.0.0-beta.6
@ai-sdk/elevenlabs 3.0.0-beta.11
@ai-sdk/fal 3.0.0-beta.11
@ai-sdk/fireworks 3.0.0-beta.14
@ai-sdk/gateway 4.0.0-beta.31
@ai-sdk/gladia 3.0.0-beta.11
@ai-sdk/google 4.0.0-beta.23
@ai-sdk/google-vertex 5.0.0-beta.31
@ai-sdk/groq 4.0.0-beta.14
@ai-sdk/huggingface 2.0.0-beta.14
@ai-sdk/hume 3.0.0-beta.11
@ai-sdk/klingai 4.0.0-beta.12
@ai-sdk/langchain 3.0.0-beta.61
@ai-sdk/llamaindex 3.0.0-beta.61
@ai-sdk/lmnt 3.0.0-beta.11
@ai-sdk/luma 3.0.0-beta.11
@ai-sdk/mcp 2.0.0-beta.14
@ai-sdk/mistral 4.0.0-beta.13
@ai-sdk/moonshotai 3.0.0-beta.14
@ai-sdk/open-responses 2.0.0-beta.12
@ai-sdk/openai 4.0.0-beta.21
@ai-sdk/openai-compatible 3.0.0-beta.14
@ai-sdk/otel 1.0.0-beta.7
@ai-sdk/perplexity 4.0.0-beta.14
@ai-sdk/prodia 2.0.0-beta.14
@ai-sdk/provider 4.0.0-beta.6
@ai-sdk/provider-utils 5.0.0-beta.10
@ai-sdk/react 4.0.0-beta.61
@ai-sdk/replicate 3.0.0-beta.12
@ai-sdk/revai 3.0.0-beta.12
@ai-sdk/rsc 3.0.0-beta.62
@ai-sdk/svelte 5.0.0-beta.61
@ai-sdk/togetherai 3.0.0-beta.14
@ai-sdk/valibot 3.0.0-beta.10
@ai-sdk/vercel 3.0.0-beta.14
@ai-sdk/vue 4.0.0-beta.61
@ai-sdk/xai 4.0.0-beta.23

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 documentation Improvements or additions to documentation feature New feature or request provider/anthropic Issues related to the @ai-sdk/anthropic provider provider/google Issues related to the @ai-sdk/google provider provider/openai Issues related to the @ai-sdk/openai provider provider/xai Issues related to the @ai-sdk/xai provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for uploading media files (e.g. images, audio, documents) via abstraction with new top-level API

2 participants