Skip to content

Accept auth_token in AnthropicFoundry.__init__ so .copy() doesn't crash#1636

Open
Kymi808 wants to merge 1 commit into
anthropics:mainfrom
Kymi808:fix/foundry-copy-accept-auth-token
Open

Accept auth_token in AnthropicFoundry.__init__ so .copy() doesn't crash#1636
Kymi808 wants to merge 1 commit into
anthropics:mainfrom
Kymi808:fix/foundry-copy-accept-auth-token

Conversation

@Kymi808
Copy link
Copy Markdown

@Kymi808 Kymi808 commented Jun 1, 2026

Summary

Calling .copy() on an AnthropicFoundry (or AsyncAnthropicFoundry) client always raises:

TypeError: AnthropicFoundry.__init__() got an unexpected keyword argument 'auth_token'

The Foundry copy() overload (src/anthropic/lib/foundry.py:204) declares an auth_token parameter 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 the call exploded. The async client had the identical bug.

Trivial repro:

from anthropic import AnthropicFoundry
AnthropicFoundry(api_key="…", resource="…").copy()
# TypeError: AnthropicFoundry.__init__() got an unexpected keyword argument 'auth_token'

Fix

Mirror the existing pattern in AnthropicAWS / AsyncAnthropicAWS, which already accept auth_token for exactly this reason (src/anthropic/lib/aws/_client.py:51"Passed through to parent but not used for AWS auth"). The implementation __init__ of both AnthropicFoundry and AsyncAnthropicFoundry now accepts auth_token: str | None = None and forwards it to super().__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 @overload signatures are left as-is (no public construction option).

Test plan

Added test_copy_does_not_crash to both TestAnthropicFoundry and TestAsyncAnthropicFoundry in tests/lib/test_azure.py. They instantiate a client, call .copy() (and .copy(timeout=...)), and assert the result is a properly typed AnthropicFoundry / AsyncAnthropicFoundry.

  • On main: both tests fail with TypeError: ... got an unexpected keyword argument 'auth_token'.
  • With this change: pytest tests/lib/test_azure.py → 11 passed.
  • ./scripts/lint reports no new errors in the changed files; ruff check and ruff format --check clean.

`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.
@Kymi808 Kymi808 requested a review from a team as a code owner June 1, 2026 20:09
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.

1 participant