Calling Claude on Microsoft Foundry from Python doesn't require a Foundry-specific SDK or hand-rolled HTTP. Anthropic's standard anthropic package ships a dedicated client class, AnthropicFoundry, that knows Foundry's endpoint shape and authentication. Everything after the constructor — messages.create, streaming, tool use — looks exactly like first-party Claude API code, which makes moving between platforms mostly a one-line change.
Install and prerequisites
The client lives in the base package (Python 3.8+):
pip install -U "anthropic"
You also need a Foundry resource with at least one Claude deployment in it, and either an API key or an Entra ID identity with access. If you don't have those yet, start with deploying Claude models in Foundry.
The constructor: resource or base_url, never both
The client needs to know which Foundry resource to call. There are two mutually exclusive ways to say so. Pass resource="example-resource" and the SDK builds the URL for you (https://example-resource.services.ai.azure.com/anthropic/), or pass the full base_url yourself — the value shown as Target URI on your deployment's Details tab in the Foundry portal. Use resource for the common case; use base_url when the endpoint differs from the standard shape.
import os
from anthropic import AnthropicFoundry
client = AnthropicFoundry(
api_key=os.environ.get("ANTHROPIC_FOUNDRY_API_KEY"),
resource="example-resource",
)
message = client.messages.create(
model="claude-sonnet-5", # your deployment name
max_tokens=1024,
messages=[{"role": "user", "content": "Summarize our meeting notes."}],
)
print(message.content)
Two things deserve attention. First, model takes your deployment name, not an abstract catalog ID — it defaults to the bare model ID (like claude-sonnet-5) at deploy time, but if someone customized it, use that custom name. Second, the response follows the standard Claude API format, including the usage object, so downstream parsing code is portable across platforms.
Configuration via environment variables
You can drop the constructor arguments entirely: the SDK auto-reads ANTHROPIC_FOUNDRY_API_KEY, ANTHROPIC_FOUNDRY_RESOURCE, and ANTHROPIC_FOUNDRY_BASE_URL. Twelve-factor deployments can construct AnthropicFoundry() with no arguments and inject everything through the environment — handy for keeping dev and prod code identical.
Skipping API keys with Entra ID
For workloads already inside Azure, the client also accepts an Entra ID token provider instead of a key, via the azure_ad_token_provider parameter with DefaultAzureCredential from the Azure Identity library. The full pattern, including token scopes and the RBAC roles to assign, is in authenticating with Microsoft Entra ID.
400 Bad Request against a feature that works fine on the first-party API may mean your deployment is Hosted on Azure and the feature (structured outputs, server-side tools, Files API) needs a Hosted on Anthropic deployment.What to expect beyond the first call
Streaming, tool use, PDF input, prompt caching, extended thinking, and 1M context are GA on Foundry, and token counting is available at POST /v1/messages/count_tokens — but some other features are still beta on Foundry; see Foundry beta caveats. Also plan your retry logic knowing Foundry does not return Anthropic's standard anthropic-ratelimit-* response headers — use exponential backoff on 429s and Azure monitoring instead, as covered in understanding Foundry quota types. For debugging, log the request-id and apim-request-id response headers; support uses both to trace a request across Anthropic and Azure systems.
One SDK footnote for polyglot teams: Foundry is supported by the Python, TypeScript, C#, Java, and PHP SDKs, but not currently by the Go and Ruby SDKs.
Where to go next
See the sibling guides for TypeScript, .NET, and Java, or jump to the quickstart for the platform-by-platform first call.