diff --git a/src/anthropic/lib/foundry.py b/src/anthropic/lib/foundry.py index fde5be54..3ce866eb 100644 --- a/src/anthropic/lib/foundry.py +++ b/src/anthropic/lib/foundry.py @@ -126,6 +126,10 @@ def __init__( resource: str | None = None, api_key: str | None = None, azure_ad_token_provider: AzureADTokenProvider | None = None, + # Passed through to parent but not used for Foundry auth; accepted so + # the parent's `copy()` (which forwards `auth_token=self.auth_token`) + # doesn't raise TypeError when called on a Foundry client. + auth_token: str | None = None, webhook_key: str | None = None, base_url: str | None = None, timeout: float | Timeout | None | NotGiven = NOT_GIVEN, @@ -166,6 +170,7 @@ def __init__( super().__init__( api_key=api_key, + auth_token=auth_token, webhook_key=webhook_key, base_url=base_url, timeout=timeout, @@ -309,6 +314,10 @@ def __init__( resource: str | None = None, api_key: str | None = None, azure_ad_token_provider: AsyncAzureADTokenProvider | None = None, + # Passed through to parent but not used for Foundry auth; accepted so + # the parent's `copy()` (which forwards `auth_token=self.auth_token`) + # doesn't raise TypeError when called on a Foundry client. + auth_token: str | None = None, webhook_key: str | None = None, base_url: str | None = None, timeout: float | Timeout | None | NotGiven = NOT_GIVEN, @@ -349,6 +358,7 @@ def __init__( super().__init__( api_key=api_key, + auth_token=auth_token, webhook_key=webhook_key, base_url=base_url, timeout=timeout, diff --git a/tests/lib/test_azure.py b/tests/lib/test_azure.py index ec3ef7b1..f95a0750 100644 --- a/tests/lib/test_azure.py +++ b/tests/lib/test_azure.py @@ -65,6 +65,20 @@ def test_missing_resource_error(self) -> None: api_key="test-key", ) + def test_copy_does_not_crash(self) -> None: + """Regression: ``copy()`` forwards ``auth_token`` via the parent client, + so ``AnthropicFoundry.__init__`` must accept it (passed through but + unused), mirroring ``AnthropicAWS``. Previously raised + ``TypeError: ... got an unexpected keyword argument 'auth_token'``. + """ + client = AnthropicFoundry(api_key="test-key", resource="example-resource") + copied = client.copy() + assert isinstance(copied, AnthropicFoundry) + assert copied.api_key == "test-key" + + copied_with_override = client.copy(timeout=30) + assert copied_with_override.timeout == 30 + class TestAsyncAnthropicFoundry: @pytest.mark.asyncio @@ -104,3 +118,17 @@ async def test_initialization_from_environment_variables(self, monkeypatch: pyte assert client.api_key == "env-key" assert "env-resource.services.ai.azure.com" in str(client.base_url) + + def test_copy_does_not_crash(self) -> None: + """Regression: ``copy()`` forwards ``auth_token`` via the parent client, + so ``AsyncAnthropicFoundry.__init__`` must accept it (passed through + but unused), mirroring ``AsyncAnthropicAWS``. Previously raised + ``TypeError: ... got an unexpected keyword argument 'auth_token'``. + """ + client = AsyncAnthropicFoundry(api_key="test-key", resource="example-resource") + copied = client.copy() + assert isinstance(copied, AsyncAnthropicFoundry) + assert copied.api_key == "test-key" + + copied_with_override = client.copy(timeout=30) + assert copied_with_override.timeout == 30