SDKs & Developer Experience

C# SDK Quickstart: NuGet, Client Setup, and First Response

Microsoft-shop enterprises can call Claude from the .NET code they already ship — with one licensing-history detail worth knowing before your package audit.

Claude 3P 101 · Updated July 2026 · Unofficial guide

Anthropic publishes an official C# SDK as the NuGet package named simply Anthropic. It targets .NET Standard 2.0 and newer, which in practice means it runs across modern .NET as well as older .NET Framework applications — a genuinely useful property in enterprises where the line-of-business estate spans fifteen years of runtime versions.

One history note before you install

The Anthropic package on NuGet is official as of version 10 and later. Earlier versions were community-maintained under a different package name. This matters for two audiences: your security team running package provenance checks (pin to version 10+ and verify the publisher), and developers following older blog posts or Stack Overflow answers whose code may reference the community-era API. When in doubt, the official repository at github.com/anthropics/anthropic-sdk-csharp is the source of truth.

Step 1: Install the package

dotnet add package Anthropic

That is the whole install. Pin the version in your project file the way you would any dependency, so SDK upgrades happen when you choose to test them.

Step 2: Create the client

AnthropicClient client = new(); // reads ANTHROPIC_API_KEY from the environment

The parameterless constructor reads the ANTHROPIC_API_KEY environment variable — the pattern to prefer, since the secret never appears in code. If your configuration system supplies the key another way, set it explicitly with an object initializer: new() { ApiKey = "..." }, feeding the value from your secret store rather than a literal.

The key itself is created in the Claude Console under Settings → API keys. API keys are long-lived — they have no expiry — so store them in a secrets manager (Azure Key Vault is the natural home in a Microsoft shop), rotate periodically, and revoke on any suspected leak. For production workloads running in cloud platforms or CI/CD pipelines, Anthropic recommends Workload Identity Federation, which exchanges your platform's identity token for short-lived Claude API credentials, over long-lived keys.

Step 3: First response

Requests go through the messages resource, asynchronously:

var message = await client.Messages.Create(parameters);

The parameters object carries the three essentials of every Claude request: the model ID (claude-sonnet-5 is the balanced workhorse; claude-opus-4-8 is recommended for complex enterprise and agentic work; claude-haiku-4-5 is the fast, low-cost tier), a max_tokens cap on reply length, and the conversation messages as role/content pairs. The repository README shows the current parameter-builder syntax — copy it from there, since it evolves with releases.

What returns is a structured message object, not a bare string: the reply content (as a list of content blocks, because responses can mix text with tool-use requests), the reason generation stopped, and input/output token counts. Log those token counts from the first deployment — they are the raw material for cost attribution, and retrofitting usage logging later is always more painful than doing it on day one.

Fits your existing patterns: the client is async-first and injectable. Register it with your dependency-injection container as a singleton-style service, wrap it behind an interface your code owns, and stubbing Claude in unit tests becomes trivial.

C# and the third-party platforms

The Anthropic package targets Anthropic's first-party Claude API. If you want Claude through your Azure estate instead, that is Microsoft Foundry — see the Foundry client setup guide and Foundry from .NET. For Claude Platform on AWS, a beta companion package (Anthropic.Aws, client class AnthropicAwsClient) handles AWS SigV4 signing and workspace configuration. For Amazon Bedrock or Google Vertex AI from C#, consult those platforms' own SDK documentation rather than assuming client classes exist in this package.

Where to go next

Read API key authentication and keeping secrets out of code, then compare deployment doors on the platform overview — for many .NET shops the real decision is first-party API versus Foundry.

Sources