Skip to content

fix(anthropic): send user as metadata.user_id - #7970

Open
omChauhanDev wants to merge 1 commit into
livekit:mainfrom
omChauhanDev:fix/anthropic-user-metadata
Open

omChauhanDev wants to merge 1 commit into
livekit:mainfrom
omChauhanDev:fix/anthropic-user-metadata

Conversation

@omChauhanDev

Copy link
Copy Markdown
Contributor

Problem

anthropic.LLM(user=...) breaks every chat request. chat() passes user straight through to messages.create() and beta.messages.create(), but neither method accepts a user argument, so the call raises TypeError: AsyncMessages.create() got an unexpected keyword argument 'user' before any request is sent. LLMStream._run wraps it in a retryable APIConnectionError, so it is handled like a network failure: the request is attempted 4 times, then fails, and an agent using this LLM never replies.

Changes

user is now sent as metadata.user_id, the Messages API field for an external user identifier, which both methods accept. Requests without user are unchanged. Added a test in tests/test_plugin_anthropic_request.py.

The SDK has no `user` parameter, so setting it made every chat request fail with a TypeError before anything was sent.
@omChauhanDev
omChauhanDev requested a review from a team as a code owner October 20, 2026 05:32

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@longcw longcw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good to me! something nit:


if is_given(self._opts.user):
extra["user"] = self._opts.user
extra["metadata"] = {"user_id": self._opts.user}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: if extra_kwargs already contains metadata, it is replaced. Could you merge into it instead, e.g. extra["metadata"] = {**extra.get("metadata", {}), "user_id": self._opts.user}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants