Anthropic 2.0.1-dev.8

Anthropic

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on OpenAPI specification using OpenApiGenerator
  • Automatic releases of new preview versions if there was an update to the OpenAPI specification
  • Source generator to define tools natively through C# interfaces
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • Support .Net Framework/.Net Standard 2.0
  • Supporting Microsoft.Extensions.AI

Usage

using Anthropic;

using var client = new AnthropicClient(apiKey);

var response = await client.CreateMessageAsync(
    model: CreateMessageRequestModel.Claude35Sonnet20240620,
    messages: [
        "What's the weather like today?",
        "Sure! Could you please provide me with your location?".AsAssistantMessage(),
        "Dubai, UAE",
    ],
    maxTokens: 250);

Tools

using CSharpToJsonSchema;

public enum Unit
{
    Celsius,
    Fahrenheit,
}

public class Weather
{
    public string Location { get; set; } = string.Empty;
    public double Temperature { get; set; }
    public Unit Unit { get; set; }
    public string Description { get; set; } = string.Empty;
}

[GenerateJsonSchema]
public interface IWeatherFunctions
{
    [Description("Get the current weather in a given location")]
    public Weather GetCurrentWeather(
        [Description("The city and state, e.g. San Francisco, CA")] string location,
        Unit unit = Unit.Celsius);
    
    [Description("Get the current weather in a given location")]
    public Task<Weather> GetCurrentWeatherAsync(
        [Description("The city and state, e.g. San Francisco, CA")] string location,
        Unit unit = Unit.Celsius,
        CancellationToken cancellationToken = default);
}

public class WeatherService : IWeatherFunctions
{
    public Weather GetCurrentWeather(string location, Unit unit = Unit.Celsius)
    {
        return new Weather
        {
            Location = location,
            Temperature = 22.0,
            Unit = unit,
            Description = "Sunny",
        };
    }
    
    public Task<Weather> GetCurrentWeatherAsync(string location, Unit unit = Unit.Celsius, CancellationToken cancellationToken = default)
    {
        return Task.FromResult(new Weather
        {
            Location = location,
            Temperature = 22.0,
            Unit = unit,
            Description = "Sunny",
        });
    }
}
using Anthropic;

using var client = new AnthropicClient(apiKey);

var service = new WeatherService();
var tools = service.AsTools();

List<Message> messages = ["What is the current temperature in Dubai, UAE in Celsius?"];

var response = await client.CreateMessageAsync(
    model: CreateMessageRequestModel.Claude35Sonnet20240620,
    messages: messages,
    maxTokens: 300,
    system: "You are a helpful weather assistant.",
    toolChoice: new ToolChoice
    {
        Type = ToolChoiceType.Auto,
    },
    tools: tools);

messages.Add(response.AsRequestMessage());

foreach (var toolUse in response.Content.Value2!
     .Where(x => x.IsToolUse)
     .Select(x => x.ToolUse))
{
    var json = await service.CallAsync(
        functionName: toolUse!.Name,
        argumentsAsJson: toolUse.Input.AsJson());
    messages.Add(json.AsToolCall(toolUse));
}

response = await client.CreateMessageAsync(
    model: CreateMessageRequestModel.Claude35Sonnet20240620,
    messages: messages,
    maxTokens: 300,
    system: "You are a helpful weather assistant.",
    toolChoice: new ToolChoice
    {
        Type = ToolChoiceType.Auto,
    },
    tools: tools);

Support

Priority place for bugs: https://github.com/tryAGI/Anthropic/issues
Priority place for ideas and general questions: https://github.com/tryAGI/Anthropic/discussions
Discord: https://discord.gg/Ca2xhfBf3v

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.

CodeRabbit logo

This project is supported by CodeRabbit through the Open Source Support Program.

Showing the top 20 packages that depend on Anthropic.

Packages Downloads
Anthropic.Foundry
Package Description
3
Anthropic.Foundry
Package Description
2

.NET Framework 4.6.2

.NET 8.0

.NET Standard 2.0

Version Downloads Last updated
12.11.0 3 04/04/2026
12.10.0 2 04/04/2026
12.9.0 2 03/26/2026
12.8.0 3 03/04/2026
12.7.0 2 03/06/2026
12.6.0 2 03/06/2026
12.5.0 2 03/06/2026
12.4.0 2 03/06/2026
12.3.0 2 03/06/2026
12.2.0 2 03/06/2026
12.1.0 2 03/06/2026
12.0.1 2 03/06/2026
12.0.0 2 03/06/2026
11.0.0 2 03/06/2026
10.4.0 2 03/06/2026
10.2.1 2 03/06/2026
10.1.2 2 03/06/2026
10.0.1 2 03/06/2026
3.7.1-dev.6 2 03/06/2026
3.7.1-dev.5 2 03/06/2026
3.7.1-dev.4 2 03/06/2026
3.7.1-dev.3 2 03/06/2026
3.7.0 2 03/06/2026
3.6.1-dev.4 2 03/06/2026
3.6.1-dev.2 2 03/06/2026
3.6.1-dev.1 2 03/06/2026
3.6.0 2 03/06/2026
3.5.1-dev.3 2 03/06/2026
3.5.1-dev.2 2 03/06/2026
3.5.1-dev.1 2 03/06/2026
3.5.0 2 03/06/2026
3.4.2-dev.11 2 03/06/2026
3.4.2-dev.4 2 03/06/2026
3.4.2-dev.3 2 03/06/2026
3.4.2-dev.2 2 03/06/2026
3.4.2-dev.1 2 03/06/2026
3.4.1 2 03/06/2026
3.4.1-dev.11 2 03/06/2026
3.4.1-dev.10 2 03/06/2026
3.4.1-dev.8 2 03/06/2026
3.4.1-dev.7 2 03/06/2026
3.4.1-dev.6 2 03/06/2026
3.4.1-dev.5 2 03/06/2026
3.4.1-dev.4 2 03/06/2026
3.4.0 2 03/06/2026
3.3.1-dev.1 2 03/06/2026
3.3.0 2 03/06/2026
3.2.1-dev.10 2 03/06/2026
3.2.1-dev.7 2 03/06/2026
3.2.0 2 03/06/2026
3.1.1-dev.8 2 03/06/2026
3.1.1-dev.6 2 03/06/2026
3.1.0 2 03/06/2026
3.0.0 2 03/06/2026
2.1.2-dev.4 2 03/06/2026
2.1.2-dev.3 2 03/06/2026
2.0.1-dev.11 2 03/06/2026
2.0.1-dev.10 2 03/06/2026
2.0.1-dev.9 2 03/06/2026
2.0.1-dev.8 2 03/06/2026
2.0.1-dev.3 2 03/06/2026
2.0.1-dev.2 2 03/06/2026
2.0.1-dev.1 2 03/06/2026
2.0.0 2 03/06/2026
1.4.5-dev.5 2 03/06/2026
1.4.5-dev.1 2 03/06/2026
1.4.4 2 03/06/2026
1.4.3-dev.1 2 03/06/2026
1.4.2 2 03/06/2026
1.4.1 2 03/06/2026
1.3.0 2 03/06/2026
1.2.1-dev.18 2 03/06/2026
1.2.1-dev.14 2 03/06/2026
1.2.1-dev.13 2 03/06/2026
1.2.1-dev.10 2 03/06/2026
1.2.1-dev.4 2 03/06/2026
1.2.0 2 03/06/2026
1.1.1-dev.13 2 03/06/2026
1.1.1-dev.12 2 03/06/2026
1.1.1-dev.10 2 03/06/2026
1.1.1-dev.9 2 03/06/2026
1.1.1-dev.8 2 03/06/2026
1.1.1-dev.7 2 03/06/2026
1.1.1-dev.2 2 03/06/2026
1.1.1-dev.1 2 03/06/2026
1.1.0 2 03/06/2026
1.0.2-dev.1 2 03/06/2026
1.0.1 2 03/06/2026
1.0.0 2 03/06/2026
0.4.1-dev.6 2 03/06/2026
0.4.1-dev.2 2 03/06/2026
0.4.0 2 03/06/2026
0.3.1 2 03/06/2026
0.3.0 2 03/06/2026
0.2.0 2 03/06/2026
0.2.0-alpha03 2 03/06/2026
0.1.0 2 03/06/2026
0.0.0-dev.35 2 03/06/2026