AI21 0.0.0-dev.251

This is a prerelease version of AI21.
There is a newer version of this package available.
See the version list below for details.
dotnet add package AI21 --version 0.0.0-dev.251
                    
NuGet\Install-Package AI21 -Version 0.0.0-dev.251
                    
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="AI21" Version="0.0.0-dev.251" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AI21" Version="0.0.0-dev.251" />
                    
Directory.Packages.props
<PackageReference Include="AI21" />
                    
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 AI21 --version 0.0.0-dev.251
                    
#r "nuget: AI21, 0.0.0-dev.251"
                    
#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.
#:package AI21@0.0.0-dev.251
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AI21&version=0.0.0-dev.251&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AI21&version=0.0.0-dev.251&prerelease
                    
Install as a Cake Tool

AI21

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on official OpenAPI specification using OpenApiGenerator
  • Same day update to support new features
  • Updated and supported automatically if there are no breaking changes
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • Support .Net Framework/.Net Standard 2.0
  • Microsoft.Extensions.AI IChatClient support

Usage

using AI21;

usung var api = new Ai21Client(apiKey);

await api.Chat.V1J2UltraChatAsync(
    messages:
    [
        new ChatMessage
        {
            Text = "Hello",
            Role = RoleType.User,
        }
    ],
    system: string.Empty,
    cancellationToken: CancellationToken.None);

Microsoft.Extensions.AI

The SDK implements IChatClient:

using AI21;
using Microsoft.Extensions.AI;

IChatClient chatClient = new Ai21Client(apiKey);

var response = await chatClient.GetResponseAsync(
    [new ChatMessage(ChatRole.User, "Hello!")],
    new ChatOptions { ModelId = "jamba-1.5-mini" });

Console.WriteLine(response.Text);

Chat Client Five Random Words Streaming

using var client = GetAuthorizedClient();

IChatClient chatClient = client;
var updates = chatClient.GetStreamingResponseAsync(
    [
        new ChatMessage(ChatRole.User, "Generate 5 random words.")
    ],
    new ChatOptions
    {
        ModelId = "jamba-large",
    });

var deltas = new List<string>();
await foreach (var update in updates)
{
    if (!string.IsNullOrWhiteSpace(update.Text))
    {
        deltas.Add(update.Text);
    }
}

Chat Client Five Random Words

using var client = GetAuthorizedClient();

IChatClient chatClient = client;
var response = await chatClient.GetResponseAsync(
    [
        new ChatMessage(ChatRole.User, "Generate 5 random words.")
    ],
    new ChatOptions
    {
        ModelId = "jamba-large",
    });

Chat Client Get Service Returns Chat Client Metadata

using var client = CreateTestClient();
IChatClient chatClient = client;

var metadata = chatClient.GetService<ChatClientMetadata>();

Chat Client Get Service Returns Null For Unknown Key

using var client = CreateTestClient();
IChatClient chatClient = client;

var result = chatClient.GetService<ChatClientMetadata>(serviceKey: "unknown");

Chat Client Get Service Returns Self

using var client = CreateTestClient();
IChatClient chatClient = client;

var self = chatClient.GetService<Ai21Client>();

Chat Client Tool Calling Multi Turn

using var client = GetAuthorizedClient();
IChatClient chatClient = client;

var getWeatherTool = AIFunctionFactory.Create(
    (string location) => $"The weather in {location} is sunny, 72°F",
    "GetWeather",
    "Gets the current weather for a location");

var messages = new List<ChatMessage>
{
    new(ChatRole.User, "What's the weather in Seattle?"),
};

var options = new ChatOptions
{
    ModelId = "jamba-large",
    Tools = [getWeatherTool],
};

// First turn: model should call the tool
var response = await chatClient.GetResponseAsync(messages, options);

var functionCall = response.Messages
    .SelectMany(m => m.Contents)
    .OfType<FunctionCallContent>()
    .FirstOrDefault();

// Add assistant response with tool call and tool result
messages.AddRange(response.Messages);

var toolResult = await getWeatherTool.InvokeAsync(
    functionCall!.Arguments is { } args ? new AIFunctionArguments(args) : null);

messages.Add(new ChatMessage(ChatRole.Tool,
[
    new FunctionResultContent(functionCall.CallId, toolResult),
]));

// Second turn: model should respond with the weather info
var finalResponse = await chatClient.GetResponseAsync(messages, options);

Chat Client Tool Calling Single Turn

using var client = GetAuthorizedClient();
IChatClient chatClient = client;

var getWeatherTool = AIFunctionFactory.Create(
    (string location) => $"The weather in {location} is sunny, 72°F",
    "GetWeather",
    "Gets the current weather for a location");

var response = await chatClient.GetResponseAsync(
    [new ChatMessage(ChatRole.User, "What's the weather in Seattle?")],
    new ChatOptions
    {
        ModelId = "jamba-large",
        Tools = [getWeatherTool],
    });

var functionCall = response.Messages
    .SelectMany(m => m.Contents)
    .OfType<FunctionCallContent>()
    .FirstOrDefault();

Chat Client Tool Calling Streaming

using var client = GetAuthorizedClient();
IChatClient chatClient = client;

var getWeatherTool = AIFunctionFactory.Create(
    (string location) => $"The weather in {location} is sunny, 72°F",
    "GetWeather",
    "Gets the current weather for a location");

var updates = chatClient.GetStreamingResponseAsync(
    [new ChatMessage(ChatRole.User, "What's the weather in Seattle?")],
    new ChatOptions
    {
        ModelId = "jamba-large",
        Tools = [getWeatherTool],
    });

var functionCalls = new List<FunctionCallContent>();
await foreach (var update in updates)
{
    functionCalls.AddRange(update.Contents.OfType<FunctionCallContent>());
}

Test

using var api = GetAuthorizedClient();

// await api.Completion.V1J2UltraCompleteAsync(
//     messages:
//     [
//         new ChatMessage
//         {
//             Text = "Hello",
//             Role = RoleType.User,
//         }
//     ],
//     system: string.Empty,
//     cancellationToken: CancellationToken.None);

Support

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

Acknowledgments

JetBrains logo

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

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 413 8/1/2023
0.0.0-dev.264 34 4/1/2026
0.0.0-dev.261 44 3/29/2026
0.0.0-dev.260 41 3/29/2026
0.0.0-dev.255 126 3/28/2026
0.0.0-dev.253 37 3/28/2026
0.0.0-dev.252 38 3/28/2026
0.0.0-dev.251 38 3/28/2026
0.0.0-dev.250 45 3/27/2026
0.0.0-dev.242 40 3/20/2026
0.0.0-dev.239 35 3/20/2026
0.0.0-dev.237 35 3/20/2026
0.0.0-dev.236 34 3/19/2026
0.0.0-dev.234 36 3/19/2026
0.0.0-dev.232 38 3/19/2026
0.0.0-dev.231 33 3/19/2026
0.0.0-dev.230 38 3/19/2026
0.0.0-dev.228 33 3/19/2026
0.0.0-dev.227 36 3/19/2026
0.0.0-dev.226 34 3/19/2026
Loading failed