Backport: feat (provider/anthropic): support passing metadata.user_id#13783
Merged
vercel-ai-sdk[bot] merged 1 commit intorelease-v6.0from Mar 24, 2026
Merged
Conversation
## Background The Anthropic API supports passing metadata with requests, including a `user_id` field for tracking end-users. This feature was not previously supported in the AI SDK's Anthropic provider. ## Changes Added support for passing `metadata.userId` to Anthropic models across all providers (direct Anthropic, Amazon Bedrock, and Google Vertex). The `userId` field is mapped to the Anthropic API's `user_id` parameter and should contain an external identifier like a UUID or hash value without PII. ## Manual Verification Created and tested an example that demonstrates passing metadata with a user ID to the Anthropic provider. The metadata is correctly transformed from camelCase `userId` to snake_case `user_id` in the API request. ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [x] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review)
4 tasks
shaper
approved these changes
Mar 24, 2026
Contributor
Author
|
|
Contributor
Author
shaper
added a commit
that referenced
this pull request
Mar 24, 2026
…ta.user_id (#13785) This is an automated backport of #13783 to the release-v5.0 branch. FYI @vercel-ai-sdk[bot] This backport has conflicts that need to be resolved manually. ### `git cherry-pick` output ``` Auto-merging content/providers/01-ai-sdk-providers/05-anthropic.mdx Auto-merging content/providers/01-ai-sdk-providers/08-amazon-bedrock.mdx Auto-merging content/providers/01-ai-sdk-providers/16-google-vertex.mdx CONFLICT (file location): examples/ai-functions/src/generate-text/anthropic/metadata.ts added in 05b8ca2 (Backport: feat (provider/anthropic): support passing metadata.user_id (#13783)) inside a directory that was renamed in HEAD, suggesting it should perhaps be moved to examples/ai-core/src/generate-text/metadata.ts. Auto-merging packages/anthropic/src/anthropic-messages-language-model.test.ts Auto-merging packages/anthropic/src/anthropic-messages-language-model.ts Auto-merging packages/anthropic/src/anthropic-messages-options.ts CONFLICT (content): Merge conflict in packages/anthropic/src/anthropic-messages-options.ts error: could not apply 05b8ca2... Backport: feat (provider/anthropic): support passing metadata.user_id (#13783) hint: After resolving the conflicts, mark them with hint: "git add/rm <pathspec>", then run hint: "git cherry-pick --continue". hint: You can instead skip this commit with "git cherry-pick --skip". hint: To abort and get back to the state before "git cherry-pick", hint: run "git cherry-pick --abort". hint: Disable this message with "git config set advice.mergeConflict false" ``` --------- Co-authored-by: vercel-ai-sdk[bot] <225926702+vercel-ai-sdk[bot]@users.noreply.github.com> Co-authored-by: Walter Korman <shaper@vercel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an automated backport of #13782 to the release-v6.0 branch. FYI @shaper