Microsoft Foundry in Practice

Calling Claude on Foundry from .NET and C#

.NET shops are Foundry's natural audience: the identity, hosting, and billing story is already Azure-shaped. Anthropic's C# SDK closes the last gap.

Claude 3P 101 · Updated July 2026 · Unofficial guide

If your organization builds on .NET, Microsoft Foundry is the lowest-friction way to reach Claude: your Azure subscription handles procurement and billing, Entra ID handles identity, and Anthropic provides an official C# SDK. Foundry is supported by Anthropic's C#, Java, PHP, Python, and TypeScript SDKs (Go and Ruby are not currently supported), and the C# support ships as the Anthropic.Foundry package.

Getting the client configured

Add the Anthropic.Foundry package to your project via NuGet. Configuration follows the same model as every other Anthropic Foundry SDK, so two values identify your endpoint, and they are mutually exclusive ways of saying the same thing:

For credentials, the Anthropic SDKs read three environment variables automatically: ANTHROPIC_FOUNDRY_API_KEY, ANTHROPIC_FOUNDRY_RESOURCE, and ANTHROPIC_FOUNDRY_BASE_URL. In an ASP.NET Core service, injecting those through your configuration provider keeps secrets out of source control; for the exact constructor overloads and options types, consult the package documentation, since Anthropic's platform docs describe the C# package at a higher level than the Python one.

Request patterns

Requests use the standard Claude Messages API: you specify a model, a token cap, and a list of messages, and Foundry returns the standard Claude response format, including the usage object with token counts — the same shape on every platform, which keeps parsing and cost-tracking code portable. Streaming and tool use are generally available on Foundry, and token counting is exposed at POST /v1/messages/count_tokens.

The value you pass as the model is your deployment name — set when the deployment was created, immutable afterward, and defaulting to a bare model ID such as claude-sonnet-5 or claude-opus-4-8. If your platform team customized deployment names, use theirs. Background on deployments, hosting versions, and model lifecycle is in deploying Claude models in Foundry.

Authentication: keys now, Entra ID for production

An Azure-issued API key (from the deployment's Details tab, sent as the api-key or x-api-key header over REST) gets you running quickly. For production .NET services on Azure, prefer Microsoft Entra ID: a bearer token in the Authorization header, obtained through the Azure Identity library's DefaultAzureCredential, which automatically uses the managed identity of your App Service, Functions app, or AKS workload. Access is then controlled by Azure RBAC — a 403 usually means the calling identity is missing a role such as Cognitive Services User on the Foundry resource. Scopes and troubleshooting live in the Entra ID article.

Rule of thumb: build retry logic around plain 429 handling with exponential backoff. Foundry does not return Anthropic's anthropic-ratelimit-* headers, so your resilience layer (Polly or similar) can't read remaining-quota hints from the response — track consumption through Azure monitoring instead.

Feature coverage to plan around

Core Messages, streaming, tool use, PDF input, prompt caching, extended thinking, and 1M context are GA on Foundry, but some features (structured outputs, server-side tools like web search and code execution, the Files API) are beta and only available on Hosted on Anthropic deployments; sending them to a Hosted on Azure deployment returns 400 Bad Request by design. The Message Batches API is not available on Foundry at all. Check the Foundry feature parity article before committing a roadmap, and log the request-id and apim-request-id response headers for supportability.

Where to go next

Parallel guides exist for Python, TypeScript, and Java. For the broader platform picture, see the platforms overview.

Sources