Skip to content

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

Merged
vercel-ai-sdk[bot] merged 1 commit intorelease-v6.0from
backport-pr-13782-to-release-v6.0
Mar 24, 2026
Merged

Backport: feat (provider/anthropic): support passing metadata.user_id#13783
vercel-ai-sdk[bot] merged 1 commit intorelease-v6.0from
backport-pr-13782-to-release-v6.0

Conversation

@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

@vercel-ai-sdk vercel-ai-sdk bot commented Mar 24, 2026

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

## 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 vercel-ai-sdk bot enabled auto-merge (squash) March 24, 2026 04:11
@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 maintenance CI, internal documentation, automations, etc provider/anthropic Issues related to the @ai-sdk/anthropic provider labels Mar 24, 2026
@vercel-ai-sdk vercel-ai-sdk bot merged commit 05b8ca2 into release-v6.0 Mar 24, 2026
26 checks passed
@vercel-ai-sdk vercel-ai-sdk bot deleted the backport-pr-13782-to-release-v6.0 branch March 24, 2026 04:24
@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 added a commit that referenced this pull request Mar 24, 2026
@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 Author

vercel-ai-sdk bot commented Mar 24, 2026

⚠️ Backport to release-v5.0 created but has conflicts: #13785

@vercel-ai-sdk
Copy link
Copy Markdown
Contributor Author

vercel-ai-sdk bot commented Mar 24, 2026

🚀 Published in:

Package Version
@ai-sdk/amazon-bedrock 4.0.83
@ai-sdk/anthropic 3.0.64
@ai-sdk/google-vertex 4.0.95

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>
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 maintenance CI, internal documentation, automations, etc provider/anthropic Issues related to the @ai-sdk/anthropic provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant