Repository navigation
fix(anthropic): send user as metadata.user_id - #7970
Open
omChauhanDev wants to merge 1 commit into
Open
omChauhanDev wants to merge 1 commit into
omChauhanDev wants to merge 1 commit into
Conversation
The SDK has no `user` parameter, so setting it made every chat request fail with a TypeError before anything was sent.
longcw
approved these changes
Oct 21, 2026
longcw
left a comment
Contributor
There was a problem hiding this comment.
looks good to me! something nit:
|
|
||
| if is_given(self._opts.user): | ||
| extra["user"] = self._opts.user | ||
| extra["metadata"] = {"user_id": self._opts.user} |
Contributor
There was a problem hiding this comment.
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
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.
Problem
anthropic.LLM(user=...)breaks every chat request.chat()passesuserstraight through tomessages.create()andbeta.messages.create(), but neither method accepts auserargument, so the call raisesTypeError: AsyncMessages.create() got an unexpected keyword argument 'user'before any request is sent.LLMStream._runwraps it in a retryableAPIConnectionError, 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
useris now sent asmetadata.user_id, the Messages API field for an external user identifier, which both methods accept. Requests withoutuserare unchanged. Added a test intests/test_plugin_anthropic_request.py.