Skip to content

fix: let copied credentials replace inherited static auth#1557

Open
pragnyanramtha wants to merge 3 commits into
anthropics:mainfrom
pragnyanramtha:fix-copy-credentials-static-auth
Open

fix: let copied credentials replace inherited static auth#1557
pragnyanramtha wants to merge 3 commits into
anthropics:mainfrom
pragnyanramtha:fix-copy-credentials-static-auth

Conversation

@pragnyanramtha
Copy link
Copy Markdown

Summary

  • stop copy(credentials=...), copy(config=...), and copy(profile=...) from carrying over an inherited api_key or auth_token unless the caller explicitly passes a static credential again
  • keep explicit static credentials shadowing copied/inherited credential providers unchanged
  • add sync and async regression coverage for copy(credentials=...) from a statically-authenticated client

Root cause

Anthropic.copy() and AsyncAnthropic.copy() always passed api_key=api_key or self.api_key and auth_token=auth_token or self.auth_token into the new client. When a caller tried to replace a parent API key client with a credentials provider, the copied client still sent the parent X-Api-Key, so AccessTokenAuth short-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 -n0
  • uv run --frozen pytest tests/test_client.py -q -n0 -k "copy"
  • uv run --frozen ruff check src/anthropic/_client.py tests/lib/test_credentials.py
  • uv run --frozen ruff format --check src/anthropic/_client.py tests/lib/test_credentials.py
  • git diff --check

@pragnyanramtha pragnyanramtha marked this pull request as ready for review May 17, 2026 01:06
@pragnyanramtha pragnyanramtha requested a review from a team as a code owner May 17, 2026 01:06
Copilot AI review requested due to automatic review settings May 17, 2026 01:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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