Anthropic.SDK 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Anthropic.SDK --version 1.1.1
                    
NuGet\Install-Package Anthropic.SDK -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Anthropic.SDK" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Anthropic.SDK" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Anthropic.SDK" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Anthropic.SDK --version 1.1.1
                    
#r "nuget: Anthropic.SDK, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Anthropic.SDK&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Anthropic.SDK&version=1.1.1
                    
Install as a Cake Tool

Anthropic.SDK

.NET

Anthropic.SDK is an unofficial C# client designed for interacting with the Claude AI API. This powerful interface simplifies the integration of the Claude AI into your C# applications. It targets netstandard2.0, and .net6.0.

Table of Contents

Installation

Install Anthropic.SDK via the NuGet package manager:

PM> Install-Package Anthropic.SDK

API Keys

You can load the API Key from an environment variable named ANTHROPIC_API_KEY by default. Alternatively, you can supply it as a string to the AnthropicClient constructor.

IHttpClientFactory

The AnthropicClient can optionally take an IHttpClientFactory, which allows you to control elements such as retries and timeouts.

Usage

To start using the Claude AI API, simply create an instance of the AnthropicClient class.

Examples

Non-Streaming Call

Here's an example of a non-streaming call to the Claude AI API:

var client = new AnthropicClient();
var prompt = AnthropicSignals.HumanSignal + "Write me a sonnet about Joe Biden." + 
         AnthropicSignals.AssistantSignal;

var parameters = new SamplingParameters()
{
    // required    
    Model = AnthropicModels.Claude_v2_0
    Prompt = prompt,
    MaxTokensToSample = 512,

    //optional
    Temperature = 1,
    Top_k = 1,
    Top_p = 1
    StopSequences = new[] { AnthropicSignals.HumanSignal },
    Stream = false
};

var response = await client.Completions.GetClaudeCompletionAsync(parameters);

Streaming Call

The following is an example of a streaming call to the Claude AI API:

var client = new AnthropicClient();
var prompt = AnthropicSignals.HumanSignal + "Write me a sonnet about Joe Biden." + 
         AnthropicSignals.AssistantSignal;

var parameters = new SamplingParameters()
{
    MaxTokensToSample = 512,
    Prompt = prompt,
    Temperature = 0.0m,
    StopSequences = new[] { AnthropicSignals.HumanSignal },
    Stream = true,
    Model = AnthropicModels.Claude_v2
};

await foreach (var res in client.Completions.StreamClaudeCompletionAsync(parameters))
{
    Console.Write(res.Completion);
}

Contributing

Pull requests are welcome. If you're planning to make a major change, please open an issue first to discuss your proposed changes.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Anthropic.SDK:

Package Downloads
Weavy.Core

A class library containing core business logic, data access and utility methods required by Weavy.

OBotService

OBase Framework

BotSharp.Plugin.AnthropicAI

Package Description

Intent.Modules.Common.AI

Support for accessing LLMs via Semantic Kernel within Intent Architect module tasks.

TurtleShell

Yet another LLM wrapper, plan to make it work on all major LLMs and Ollama. Feel free to use, but largely a personal project

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Anthropic.SDK:

Repository Stars
SciSharp/BotSharp
AI Multi-Agent Framework in .NET
modelcontextprotocol/csharp-sdk
The official C# SDK for Model Context Protocol servers and clients. Maintained in collaboration with Microsoft.
PederHP/mcpdotnet
.NET implementation of the Model Context Protocol (MCP)
Version Downloads Last Updated
5.4.3 302 7/10/2025
5.4.2 2,818 6/28/2025
5.4.1 25,295 5/27/2025
5.4.0 717 5/25/2025
5.3.0 4,656 5/16/2025
5.2.3 4,907 5/15/2025
5.2.2 2,736 5/9/2025
5.2.1 1,294 5/9/2025
5.2.0 6,070 4/28/2025
5.1.1 22,685 4/1/2025
5.1.0 2,523 3/28/2025
5.0.0 25,948 3/20/2025
4.7.2 5,350 3/19/2025
4.7.1 22,305 3/1/2025
4.7.0 483 2/28/2025
4.6.0 18,133 2/21/2025
4.5.0 13,708 1/28/2025
4.4.4 1,599 1/23/2025
4.4.3 2,470 1/16/2025
4.4.2 43,500 12/2/2024
4.4.1 3,246 11/22/2024
4.4.0 4,592 11/20/2024
4.3.1 2,306 11/13/2024
4.3.0 5,921 10/30/2024
4.2.0 1,483 10/26/2024
4.1.1 17,521 8/30/2024
4.1.0 11,288 8/18/2024
4.0.0 6,825 8/2/2024
3.3.0 17,186 7/23/2024
3.2.3 67,823 6/21/2024
3.2.2 2,681 6/16/2024
3.2.1 8,437 4/25/2024
3.2.0 9,120 4/24/2024
3.1.0 1,190 4/17/2024
3.0.1 2,616 4/12/2024
3.0.0 429 4/11/2024
2.0.1 19,296 3/17/2024
2.0.0 4,869 3/5/2024
1.3.0 3,119 11/21/2023
1.2.0 9,883 8/19/2023
1.1.2 1,866 8/9/2023
1.1.1 1,127 7/24/2023
1.1.0 1,070 7/16/2023
1.0.0 2,212 7/1/2023

Adds model constants and signal types as well as better validations.