Skip to content

feat (provider/anthropic): support passing metadata.user_id#13782

Merged
shaper merged 1 commit intomainfrom
03-23-feat_provider_anthropic_support_passing_metadata.user_id
Mar 24, 2026
Merged

feat (provider/anthropic): support passing metadata.user_id#13782
shaper merged 1 commit intomainfrom
03-23-feat_provider_anthropic_support_passing_metadata.user_id

Conversation

@shaper
Copy link
Copy Markdown
Collaborator

@shaper shaper commented 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

  • 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)

Copy link
Copy Markdown
Collaborator Author

shaper commented Mar 24, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request provider/anthropic Issues related to the @ai-sdk/anthropic provider labels Mar 24, 2026
@shaper shaper requested review from aayush-kapoor and gr2m March 24, 2026 02:11
@shaper shaper marked this pull request as ready for review March 24, 2026 02:11
@shaper shaper merged commit 0ee8aec into main Mar 24, 2026
32 checks passed
@shaper shaper deleted the 03-23-feat_provider_anthropic_support_passing_metadata.user_id branch March 24, 2026 04:10
@shaper shaper added the backport Admins only: add this label to a pull request in order to backport it to the prior version label 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)
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 24, 2026

✅ Backport PR created: #13783

@vercel-ai-sdk vercel-ai-sdk bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Mar 24, 2026
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 24, 2026

🚀 Published in:

Package Version
@ai-sdk/amazon-bedrock 5.0.0-beta.11
@ai-sdk/anthropic 4.0.0-beta.11
@ai-sdk/google-vertex 5.0.0-beta.22

vercel-ai-sdk bot added a commit that referenced this pull request Mar 24, 2026
…#13783)

This is an automated backport of #13782 to the release-v6.0 branch. FYI
@shaper

Co-authored-by: Walter Korman <shaper@vercel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request provider/anthropic Issues related to the @ai-sdk/anthropic provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants