fix: let copied credentials replace inherited static auth#1557
Open
pragnyanramtha wants to merge 3 commits into
Open
fix: let copied credentials replace inherited static auth#1557pragnyanramtha wants to merge 3 commits into
pragnyanramtha wants to merge 3 commits into
Conversation
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.
Summary
copy(credentials=...),copy(config=...), andcopy(profile=...)from carrying over an inheritedapi_keyorauth_tokenunless the caller explicitly passes a static credential againcopy(credentials=...)from a statically-authenticated clientRoot cause
Anthropic.copy()andAsyncAnthropic.copy()always passedapi_key=api_key or self.api_keyandauth_token=auth_token or self.auth_tokeninto the new client. When a caller tried to replace a parent API key client with a credentials provider, the copied client still sent the parentX-Api-Key, soAccessTokenAuthshort-circuited and the requested provider was silently disabled.Validation
uv run --frozen pytest tests/lib/test_credentials.py -q -n0 -k "copy_with_credentials_replaces_inherited_api_key or copy_with_explicit_api_key_shadows_inherited_credentials or copy_propagates_credentials"uv run --frozen pytest tests/lib/test_credentials.py -q -n0uv run --frozen pytest tests/test_client.py -q -n0 -k "copy"uv run --frozen ruff check src/anthropic/_client.py tests/lib/test_credentials.pyuv run --frozen ruff format --check src/anthropic/_client.py tests/lib/test_credentials.pygit diff --check