Standard client: external bearer callbacks without OAuth beta coupling or placeholder credentials
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- authentication, backend-api-design
Direzione di ricerca
Read src/anthropic/_client.py and src/anthropic/lib/credentials/_auth.py and _types.py, then trace how bearer tokens, credentials, and OAuth beta headers are applied to sync and async requests. The issue lists the required behavior and transport-only reproduction; done means the standard clients support the requested auth configuration and the listed tests cover retries, streaming, cancellation, errors, and client copies.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Please support externally issued, renewable bearer tokens directly on the standard Anthropic / AsyncAnthropic clients, without requiring a platform-specific client, a placeholder credential, or an Anthropic-native OAuth beta.
This is an ergonomics and authentication-policy request, not a claim that dynamic credentials are missing. credentials= already supports synchronous/asynchronous providers, expiry caching and refresh-on-401. A plain callable bearer getter remains a different, simpler integration.
Current behavior
Verified against the released v2.3.0 source (202db72c87d7c6eaa72129c67ce67fd343a3a20c):
auth_tokenis a static string. Azure Identity'sget_bearer_token_providerreturns a callable supplying a current string, so it cannot be passed directly.- The supported
credentials=path requires an AnthropicAccessTokenprovider and automatically addsanthropic-beta: oauth-2025-04-20, even when the supplied token was issued for a different service. expires_at=Nonemeans cache indefinitely.AccessToken(getter(), expires_at=0)is the existing, documented provider-owned-caching adapter: the getter is called again for every request. It works; the request here is to remove this token-wrapping bridge and its automatic native OAuth coupling.- The SDK's
force_refreshcontract cannot be assumed to map to identity libraries whose public getter has no force-refresh parameter. - A compatible gateway may support more than one resource-key header shape. This should be explicit configuration/documentation, not a reason to require a different client type.
Live tests against a freshly provisioned Foundry Haiku 5.5 deployment accepted both native bearer-key and documented x-api-key authentication, both 2023-06-01 and 2026-10-21, and the incidental OAuth beta header. This request is therefore not claiming that Foundry currently rejects the generic SDK's native defaults; it asks to remove unnecessary authentication adapters and clarify the compatibility contract.
Existing requests: https://github.com/anthropics/anthropic-sdk-python/issues/1496 and https://github.com/anthropics/anthropic-sdk-python/pull/1516 are closed; the PR was not merged. The newer async provider support should be preserved rather than reimplemented.
Minimal transport-only reproduction
No Azure resource, token or account is required:
import time
import httpx2 as httpx
from anthropic import AccessToken, Anthropic
headers = []
def respond(request):
headers.append(request.headers)
return httpx.Response(200, json={
"id": "msg_test", "type": "message", "role": "assistant", "model": "test",
"content": [{"type": "text", "text": "OK"}], "stop_reason": "end_turn",
"stop_sequence": None, "usage": {"input_tokens": 1, "output_tokens": 1},
})
with Anthropic(
base_url="https://example.invalid/anthropic",
credentials=lambda: AccessToken("test-token", expires_at=int(time.time()) + 3600),
http_client=httpx.Client(transport=httpx.MockTransport(respond)),
max_retries=0,
) as client:
client.messages.create(model="test", max_tokens=16,
messages=[{"role": "user", "content": "Hi"}])
assert "oauth-2025-04-20" in headers[0]["anthropic-beta"]
The observation is the SDK's unconditional OAuth opt-in. It does not assert that every other endpoint rejects that header.
Requested API and acceptance criteria
- A direct, explicitly selected string bearer getter, for example
auth_token: str | Callable[[], str], and an awaited async equivalent. This would offer the same per-request behavior as the existingAccessToken(..., expires_at=0)adapter without token wrapping. Leave ordinary token caching/renewal to the provider. - Do not infer native OAuth/token-exchange semantics or add its beta header merely because a bearer token is supplied.
- Keep the advanced expiry-aware provider API, with a documented distinction between provider-owned caching, SDK-owned caching, and optional forced refresh.
- Permit explicit authentication-scheme/header selection when targeting another compatible endpoint, without a platform-specific client.
- Provide an explicit, public way to use custom HTTP authentication without triggering ambient credential discovery or needing a placeholder secret.
- Tests for native/custom base URLs, explicit credential precedence over environment/profile state, token changes across retries, async cancellation, streaming, errors and client-copy behavior.
The goal is an unchanged standard client and Messages/streaming application code. Only endpoint/model/authentication configuration and, for Microsoft Entra ID, the identity library should vary.
Source references
- https://github.com/anthropics/anthropic-sdk-python/blob/202db72c87d7c6eaa72129c67ce67fd343a3a20c/src/anthropic/_client.py
- https://github.com/anthropics/anthropic-sdk-python/blob/202db72c87d7c6eaa72129c67ce67fd343a3a20c/src/anthropic/lib/credentials/_auth.py
- https://github.com/anthropics/anthropic-sdk-python/blob/202db72c87d7c6eaa72129c67ce67fd343a3a20c/src/anthropic/lib/credentials/_types.py
- Lingua principale
- Python
- Stelle
- 4.1k
- Fork
- 915
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di anthropics/anthropic-sdk-python
-
beta_tool validation errors reach the model as "Invalid arguments for function X" with no detailForse già presa @mangeshraut712 l’ha presa 32 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
anthropics/anthropic-sdk-python#2033 · 3 commenti ·
-
`AnthropicBedrock` 2.x sends `anthropic_version: 2026-10-21`, which Bedrock rejects for Claude Sonnet 4.5, Opus 4.5 and Opus 4.6Forse già presa @charan-rathore l’ha presa 36 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
anthropics/anthropic-sdk-python#2031 · 1 commento ·
-
Three symlink tests in test_agent_toolset.py are missing the needs_symlinks markerForse già presa @okxint l’ha presa 82 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
anthropics/anthropic-sdk-python#1915 · 3 commenti ·
-
Messages.parse (and AsyncMessages.parse) don't take cache_control?Forse già presa @AlphaFDE l’ha presa 86 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
anthropics/anthropic-sdk-python#1907 · 2 commenti ·
-
Windows: os.fchmod in credential write-back bricks the OAuth refresh tokenForse già presa @OllieinCanada l’ha presa 98 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
anthropics/anthropic-sdk-python#1868 · 1 commento ·
Tutte le issue di anthropics/anthropic-sdk-python
Issue simili
-
bug harness
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mruangutai/harness#2687 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
modal-labs/modal-client#4158 ·
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 72/100
The-Swarm-Corporation/swarms-rs#168 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] SMTP listener now binds to EMAIL_PORT instead of 2525 since the gunicorn switch 5.0.3-ls373Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
linuxserver/docker-healthchecks#137 · 1 commento ·