Skip to content

feat(client): support callable auth tokens#1516

Open
wilyan09007 wants to merge 1 commit intoanthropics:mainfrom
wilyan09007:issue-1496-auth-token-provider
Open

feat(client): support callable auth tokens#1516
wilyan09007 wants to merge 1 commit intoanthropics:mainfrom
wilyan09007:issue-1496-auth-token-provider

Conversation

@wilyan09007
Copy link
Copy Markdown

What

Allows auth_token to be either a string or a zero-argument callable returning a string. Callable tokens are resolved when bearer auth headers are built, so clients can refresh externally managed tokens between requests.

Also exports the new AuthToken alias, documents the pattern in the README, and adds credential-precedence/copy coverage.

Why

Fixes #1496.

Callers using short-lived bearer tokens need a way to provide the current token without reconstructing the client for every request.

Verification / How to test

  • uv run python -m pytest tests\test_client.py -k "auth_token_callable or validate_headers" -n0
  • uv run python -m pytest tests\lib\test_credentials.py -k "auth_token_callable or explicit_auth_token_shadows or copy_with_explicit_api_key_shadows" -n0
  • uv run ruff check src\anthropic\_client.py src\anthropic\__init__.py tests\test_client.py tests\lib\test_credentials.py README.md
  • uv run pyright src\anthropic\_client.py src\anthropic\__init__.py
  • git diff --check HEAD~1..HEAD

@wilyan09007 wilyan09007 requested a review from a team as a code owner May 8, 2026 00:31
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.

Support Entra ID and other short-lived bearer tokens for enterprise auth

1 participant