Anthropic 10.0.1
Prefix ReservedSee the version list below for details.
dotnet add package Anthropic --version 10.0.1
NuGet\Install-Package Anthropic -Version 10.0.1
<PackageReference Include="Anthropic" Version="10.0.1" />
<PackageVersion Include="Anthropic" Version="10.0.1" />
<PackageReference Include="Anthropic" />
paket add Anthropic --version 10.0.1
#r "nuget: Anthropic, 10.0.1"
#:package Anthropic@10.0.1
#addin nuget:?package=Anthropic&version=10.0.1
#tool nuget:?package=Anthropic&version=10.0.1
Anthropic C# API Library
📦 Package Versioning Update
As of version 10+, the
Anthropicpackage is now the official Anthropic SDK for C# (currently in beta).Package versions 3.X and below were previously used for the tryAGI community-built SDK, which has moved to
tryAGI.Anthropic. If you need to continue using the former client in your project, please update your package reference totryAGI.Anthropic.We're grateful to the maintainers of tryAGI.Anthropic for their work serving the Claude ecosystem and C# community.
ℹ️ Beta Release
The Anthropic C# API Library is currently in beta and we're excited for you to experiment with it!
Important: While this package is versioned as 10.0+ due to the package transition described above, it should be treated as an early beta release. This library has not yet been exhaustively tested in production environments and may be missing some features you'd expect in a stable release. There may be breaking changes as we continue development.
We'd love your feedback! Please share any suggestions, bug reports, feature requests, or general thoughts by filing an issue.
The Anthropic C# SDK provides convenient access to the Anthropic REST API from applications written in C#.
The REST API documentation can be found on docs.anthropic.com.
Installation
dotnet add package Anthropic
Requirements
This library requires .NET 8 or later.
The library is currently in beta. The requirements will be lowered in the future.
Usage
See the examples directory for complete and runnable examples.
using System;
using Anthropic;
using Anthropic.Models.Messages;
AnthropicClient client = new();
MessageCreateParams parameters = new()
{
MaxTokens = 1024,
Messages =
[
new()
{
Role = Role.User,
Content = "Hello, Claude",
},
],
Model = Model.Claude3_7SonnetLatest,
};
var message = await client.Messages.Create(parameters);
Console.WriteLine(message);
Client configuration
Configure the client using environment variables:
using Anthropic;
// Configured using the ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN and ANTHROPIC_BASE_URL environment variables
AnthropicClient client = new();
Or manually:
using Anthropic;
AnthropicClient client = new() { APIKey = "my-anthropic-api-key" };
Or using a combination of the two approaches.
See this table for the available options:
| Property | Environment variable | Required | Default value |
|---|---|---|---|
APIKey |
ANTHROPIC_API_KEY |
false | - |
AuthToken |
ANTHROPIC_AUTH_TOKEN |
false | - |
BaseUrl |
ANTHROPIC_BASE_URL |
true | "https://api.anthropic.com" |
Modifying configuration
To temporarily use a modified client configuration, while reusing the same connection and thread pools, call WithOptions on any client or service:
using System;
var message = await client
.WithOptions(options =>
options with
{
BaseUrl = new("https://example.com"),
Timeout = TimeSpan.FromSeconds(42),
}
)
.Messages.Create(parameters);
Console.WriteLine(message);
Using a with expression makes it easy to construct the modified options.
The WithOptions method does not affect the original client or service.
Requests and responses
To send a request to the Anthropic API, build an instance of some Params class and pass it to the corresponding client method. When the response is received, it will be deserialized into an instance of a C# class.
For example, client.Messages.Create should be called with an instance of MessageCreateParams, and it will return an instance of Task<Message>.
Streaming
The SDK defines methods that return response "chunk" streams, where each chunk can be individually processed as soon as it arrives instead of waiting on the full response. Streaming methods generally correspond to SSE or JSONL responses.
Some of these methods may have streaming and non-streaming variants, but a streaming method will always have a Streaming suffix in its name, even if it doesn't have a non-streaming variant.
These streaming methods return IAsyncEnumerable:
using System;
using Anthropic.Models.Messages;
MessageCreateParams parameters = new()
{
MaxTokens = 1024,
Messages =
[
new()
{
Role = Role.User,
Content = "Hello, Claude",
},
],
Model = Model.Claude3_7SonnetLatest,
};
await foreach (var message in client.Messages.CreateStreaming(parameters))
{
Console.WriteLine(message);
}
Binary responses
The SDK defines methods that return binary responses, which are used for API responses that shouldn't necessarily be parsed, like non-JSON data.
These methods return HttpResponse:
using System;
using Anthropic.Models.Beta.Files;
FileDownloadParams parameters = new() { FileID = "file_id" };
var response = await client.Beta.Files.Download(parameters);
Console.WriteLine(response);
To save the response content to a file, or any Stream, use the CopyToAsync method:
using System.IO;
using var response = await client.Beta.Files.Download(parameters);
using var contentStream = await response.ReadAsStream();
using var fileStream = File.Open(path, FileMode.OpenOrCreate);
await contentStream.CopyToAsync(fileStream); // Or any other Stream
Error handling
The SDK throws custom unchecked exception types:
AnthropicApiException: Base class for API errors. See this table for which exception subclass is thrown for each HTTP status code:
| Status | Exception |
|---|---|
| 400 | AnthropicBadRequestException |
| 401 | AnthropicUnauthorizedException |
| 403 | AnthropicForbiddenException |
| 404 | AnthropicNotFoundException |
| 422 | AnthropicUnprocessableEntityException |
| 429 | AnthropicRateLimitException |
| 5xx | Anthropic5xxException |
| others | AnthropicUnexpectedStatusCodeException |
Additionally, all 4xx errors inherit from Anthropic4xxException.
AnthropicSseException: thrown for errors encountered during SSE streaming after a successful initial HTTP response.AnthropicIOException: I/O networking errors.AnthropicInvalidDataException: Failure to interpret successfully parsed data. For example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it from the response.AnthropicException: Base class for all exceptions.
Network options
Retries
The SDK automatically retries 2 times by default, with a short exponential backoff between requests.
Only the following error types are retried:
- Connection errors (for example, due to a network connectivity problem)
- 408 Request Timeout
- 409 Conflict
- 429 Rate Limit
- 5xx Internal
The API may also explicitly instruct the SDK to retry or not retry a request.
To set a custom number of retries, configure the client using the MaxRetries method:
using Anthropic;
AnthropicClient client = new() { MaxRetries = 3 };
Or configure a single method call using WithOptions:
using System;
var message = await client
.WithOptions(options =>
options with { MaxRetries = 3 }
)
.Messages.Create(parameters);
Console.WriteLine(message);
Timeouts
Requests time out after 10 minutes by default.
To set a custom timeout, configure the client using the Timeout option:
using System;
using Anthropic;
AnthropicClient client = new() { Timeout = TimeSpan.FromSeconds(42) };
Or configure a single method call using WithOptions:
using System;
var message = await client
.WithOptions(options =>
options with { Timeout = TimeSpan.FromSeconds(42) }
)
.Messages.Create(parameters);
Console.WriteLine(message);
Undocumented API functionality
The SDK is typed for convenient usage of the documented API. However, it also supports working with undocumented or not yet supported parts of the API.
Response validation
In rare cases, the API may return a response that doesn't match the expected type. For example, the SDK may expect a property to contain a string, but the API could return something else.
By default, the SDK will not throw an exception in this case. It will throw AnthropicInvalidDataException only if you directly access the property.
If you would prefer to check that the response is completely well-typed upfront, then either call Validate:
var message = client.Messages.Create(parameters);
message.Validate();
Or configure the client using the ResponseValidation option:
using Anthropic;
AnthropicClient client = new() { ResponseValidation = true };
Or configure a single method call using WithOptions:
using System;
var message = await client
.WithOptions(options =>
options with { ResponseValidation = true }
)
.Messages.Create(parameters);
Console.WriteLine(message);
Semantic versioning
⚠️ Beta Release: While this package is versioned as 10+, it is currently in beta. During the beta period, breaking changes may occur in minor or patch releases. Once the library reaches stable release, we will follow SemVer conventions more strictly.
This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:
- Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals.)
- Changes that we do not expect to impact the vast majority of users in practice.
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
We are keen for your feedback; please open an issue with questions, bugs, or suggestions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- System.Text.Json (>= 9.0.9)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Anthropic:
| Package | Downloads |
|---|---|
|
LangChain.Providers.Anthropic
Anthropic API LLM and Chat model provider. |
|
|
WarpToolkit.WinForms.AI
Preview-Version of the Winforms Ai- and RevamP -Toolkit (WARP). You need to target TFM 'net9-windows10.0.22000.0' at the least. Note, that this is a preview version and may be unstable. **DISCLAIMER** – USE AT YOUR OWN RISK This NuGet package is a personal collection of experimental ideas and proof-of-concepts by Klaus Löffelmann. It is part of an AI learning ramp-up project focused on exploring modernization strategies for Windows Forms (WinForms). The package is not production-ready and may contain bugs, incomplete features, or other issues. It is intended solely for educational and conceptual exploration. Although the author is a full-time Microsoft employee, this project is a personal initiative and is not affiliated with, endorsed by, or supported by Microsoft. Versions 0.x are released under the MIT License. Licensing terms may change for future 1.x versions and beyond. |
|
|
CToolkit.Microsoft.Extensions.AI
Alpha-Version of the WinForms AI- and Modernization-Toolkit. You need to target TFM 'net9-windows10.0.22000.0' at the least: NET 9+ and Windows version 10.0.22000.0 or higher. Use on own risk - this is a personal Hobby project, provided without support neither from Microsoft nor from the Authors. |
|
|
Richasy.AgentKernel.Connectors.Anthropic
Agent Kernel connectors for Anthropic, include Chat service. |
|
|
Anthropic.Foundry
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Anthropic:
| Repository | Stars |
|---|---|
|
rappen/FetchXMLBuilder
FetchXML Builder for XrmToolBox and Microsoft Dynamics 365 / CRM
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 11.0.0 | 1,756 | 12/2/2025 | |
| 10.4.0 | 1,266 | 11/26/2025 | |
| 10.2.1 | 1,475 | 11/21/2025 | |
| 10.1.2 | 902 | 11/18/2025 | |
| 10.0.1 | 486 | 11/18/2025 | |
| 3.7.1-dev.6 | 475 | 6/18/2025 | |
| 3.7.1-dev.5 | 455 | 6/18/2025 | |
| 3.7.1-dev.4 | 440 | 6/18/2025 | |
| 3.7.1-dev.3 | 459 | 6/18/2025 | |
| 3.7.0 | 2,687 | 6/6/2025 | |
| 3.6.1-dev.4 | 557 | 5/22/2025 | |
| 3.6.1-dev.2 | 485 | 5/19/2025 | |
| 3.6.1-dev.1 | 439 | 5/19/2025 | |
| 3.6.0 | 1,992 | 5/16/2025 | |
| 3.5.1-dev.3 | 517 | 5/16/2025 | |
| 3.5.1-dev.2 | 547 | 5/14/2025 | |
| 3.5.1-dev.1 | 544 | 5/13/2025 | |
| 3.5.0 | 586 | 5/13/2025 | |
| 3.4.2-dev.11 | 545 | 5/13/2025 | |
| 3.4.2-dev.4 | 730 | 4/21/2025 | |
| 3.4.2-dev.3 | 496 | 4/14/2025 | |
| 3.4.2-dev.2 | 563 | 4/9/2025 | |
| 3.4.2-dev.1 | 462 | 4/7/2025 | |
| 3.4.1 | 4,980 | 4/2/2025 | |
| 3.4.1-dev.11 | 464 | 3/31/2025 | |
| 3.4.1-dev.10 | 464 | 3/30/2025 | |
| 3.4.1-dev.8 | 642 | 3/21/2025 | |
| 3.4.1-dev.7 | 493 | 3/11/2025 | |
| 3.4.1-dev.6 | 500 | 3/9/2025 | |
| 3.4.1-dev.5 | 516 | 3/7/2025 | |
| 3.4.1-dev.4 | 543 | 3/5/2025 | |
| 3.4.0 | 1,095 | 2/28/2025 | |
| 3.3.1-dev.1 | 408 | 2/28/2025 | |
| 3.3.0 | 1,041 | 2/27/2025 | |
| 3.2.1-dev.10 | 409 | 2/27/2025 | |
| 3.2.1-dev.7 | 430 | 2/17/2025 | |
| 3.2.0 | 8,859 | 1/27/2025 | |
| 3.1.1-dev.8 | 393 | 1/15/2025 | |
| 3.1.1-dev.6 | 471 | 1/7/2025 | |
| 3.1.0 | 9,267 | 12/18/2024 | |
| 3.0.0 | 1,849 | 12/10/2024 | |
| 2.1.2-dev.4 | 410 | 12/10/2024 | |
| 2.1.2-dev.3 | 402 | 12/10/2024 | |
| 2.0.1-dev.11 | 513 | 11/20/2024 | |
| 2.0.1-dev.10 | 422 | 11/14/2024 | |
| 2.0.1-dev.9 | 402 | 11/13/2024 | |
| 2.0.1-dev.8 | 426 | 11/13/2024 | |
| 2.0.1-dev.3 | 448 | 10/29/2024 | |
| 2.0.1-dev.2 | 415 | 10/29/2024 | |
| 2.0.1-dev.1 | 390 | 10/28/2024 | |
| 2.0.0 | 12,151 | 10/28/2024 | |
| 1.4.5-dev.5 | 408 | 10/28/2024 | |
| 1.4.5-dev.1 | 396 | 10/28/2024 | |
| 1.4.4 | 39,970 | 10/26/2024 | |
| 1.4.3-dev.1 | 467 | 10/24/2024 | |
| 1.4.2 | 2,404 | 10/24/2024 | |
| 1.4.1 | 447 | 10/24/2024 | |
| 1.3.0 | 3,139 | 10/11/2024 | |
| 1.2.1-dev.18 | 416 | 9/23/2024 | |
| 1.2.1-dev.14 | 395 | 9/20/2024 | |
| 1.2.1-dev.13 | 401 | 9/20/2024 | |
| 1.2.1-dev.10 | 441 | 9/16/2024 | |
| 1.2.1-dev.4 | 25,724 | 8/29/2024 | |
| 1.2.0 | 12,399 | 8/22/2024 | |
| 1.1.1-dev.13 | 405 | 8/21/2024 | |
| 1.1.1-dev.12 | 415 | 8/20/2024 | |
| 1.1.1-dev.10 | 401 | 8/19/2024 | |
| 1.1.1-dev.9 | 439 | 8/19/2024 | |
| 1.1.1-dev.8 | 432 | 8/19/2024 | |
| 1.1.1-dev.7 | 428 | 8/19/2024 | |
| 1.1.1-dev.2 | 491 | 8/15/2024 | |
| 1.1.1-dev.1 | 418 | 8/13/2024 | |
| 1.1.0 | 2,856 | 8/13/2024 | |
| 1.0.2-dev.1 | 422 | 8/12/2024 | |
| 1.0.1 | 1,925 | 8/6/2024 | |
| 1.0.0 | 1,795 | 8/3/2024 | |
| 0.4.1-dev.6 | 396 | 8/6/2024 | |
| 0.4.1-dev.2 | 392 | 8/3/2024 | |
| 0.4.0 | 2,045 | 7/22/2024 | |
| 0.3.1 | 19,225 | 11/24/2023 | |
| 0.3.0 | 65,787 | 7/20/2023 | |
| 0.2.0 | 2,403 | 7/20/2023 | |
| 0.2.0-alpha03 | 480 | 11/18/2025 | |
| 0.1.0 | 1,454 | 7/15/2023 | |
| 0.0.0-dev.35 | 393 | 7/22/2024 |