Conversation
gr2m
approved these changes
Mar 24, 2026
vercel-ai-sdk bot
pushed a commit
that referenced
this pull request
Mar 24, 2026
## 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)
Contributor
|
✅ Backport PR created: #13783 |
Contributor
|
🚀 Published in:
|
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.

Background
The Anthropic API supports passing metadata with requests, including a
user_idfield for tracking end-users. This feature was not previously supported in the AI SDK's Anthropic provider.Changes
Added support for passing
metadata.userIdto Anthropic models across all providers (direct Anthropic, Amazon Bedrock, and Google Vertex). TheuserIdfield is mapped to the Anthropic API'suser_idparameter 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
userIdto snake_caseuser_idin the API request.Checklist
pnpm changesetin the project root)