Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/anthropic/lib/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions tests/lib/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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