Accept auth_token in AnthropicFoundry.__init__ so .copy() doesn't crash#1636
Open
Kymi808 wants to merge 1 commit into
Open
Accept auth_token in AnthropicFoundry.__init__ so .copy() doesn't crash#1636Kymi808 wants to merge 1 commit into
Kymi808 wants to merge 1 commit into
Conversation
`AnthropicFoundry.copy()` declares an `auth_token` parameter (line 204) and forwards it via `super().copy(auth_token=auth_token, ...)`. The parent `Anthropic.copy()` (`src/anthropic/_client.py:477-479`) then unconditionally passes `auth_token=auth_token or self.auth_token` into `self.__class__(...)`. But `AnthropicFoundry.__init__` did not accept an `auth_token` kwarg, so any call to `.copy()` on a Foundry client raised `TypeError: AnthropicFoundry.__init__() got an unexpected keyword argument 'auth_token'`. The same was true for `AsyncAnthropicFoundry`. Mirror the pattern already used in `AnthropicAWS`/`AsyncAnthropicAWS`: accept `auth_token` in the implementation `__init__` (passed through to the parent but not used for Foundry auth, since Foundry uses an API key or Azure AD token). The typing overloads are left as-is — `auth_token` is plumbing for `.copy()` compatibility, not a public construction option. Adds regression tests for the sync and async clients in tests/lib/test_azure.py.
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
Calling
.copy()on anAnthropicFoundry(orAsyncAnthropicFoundry) client always raises:The Foundry
copy()overload (src/anthropic/lib/foundry.py:204) declares anauth_tokenparameter and forwards it viasuper().copy(auth_token=auth_token, ...). The parentAnthropic.copy()(src/anthropic/_client.py:477–479) then unconditionally passesauth_token=auth_token or self.auth_tokenintoself.__class__(...). ButAnthropicFoundry.__init__did not accept anauth_tokenkwarg, so the call exploded. The async client had the identical bug.Trivial repro:
Fix
Mirror the existing pattern in
AnthropicAWS/AsyncAnthropicAWS, which already acceptauth_tokenfor exactly this reason (src/anthropic/lib/aws/_client.py:51— "Passed through to parent but not used for AWS auth"). The implementation__init__of bothAnthropicFoundryandAsyncAnthropicFoundrynow acceptsauth_token: str | None = Noneand forwards it tosuper().__init__(auth_token=auth_token, ...). Foundry's own auth uses an API key / Azure AD token, so the value is plumbing-only — that's why the@overloadsignatures are left as-is (no public construction option).Test plan
Added
test_copy_does_not_crashto bothTestAnthropicFoundryandTestAsyncAnthropicFoundryintests/lib/test_azure.py. They instantiate a client, call.copy()(and.copy(timeout=...)), and assert the result is a properly typedAnthropicFoundry/AsyncAnthropicFoundry.main: both tests fail withTypeError: ... got an unexpected keyword argument 'auth_token'.pytest tests/lib/test_azure.py→ 11 passed../scripts/lintreports no new errors in the changed files;ruff checkandruff format --checkclean.