Skip to content

feat(client): support callable auth tokens#1516

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

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

Conversation

@wilyan09007
Copy link
Copy Markdown

@wilyan09007 wilyan09007 commented May 8, 2026

Summary:
Fixes #1496 by allowing auth_token to be a string or a callable returning the current bearer token. Callable tokens are resolved when auth headers are built, so long-running clients can use refreshed tokens.

Changes:

  • Add an AuthToken alias for static and callable bearer tokens.
  • Resolve callable auth tokens per request for sync and async clients.
  • Preserve callable token behavior through copied clients.
  • Document short-lived bearer token usage in the README.
  • Add tests for callable tokens and credential precedence.

Testing instructions:

  • Run uv run python -m pytest tests\test_client.py -k "auth_token_callable or validate_headers" -n0.
  • Run 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.
  • Run uv run ruff check src\anthropic\_client.py src\anthropic\__init__.py tests\test_client.py tests\lib\test_credentials.py README.md.
  • Run uv run pyright src\anthropic\_client.py src\anthropic\__init__.py.

@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