{"id":22065422,"url":"https://github.com/tryagi/ai21","last_synced_at":"2026-04-10T22:33:15.001Z","repository":{"id":185191175,"uuid":"673115066","full_name":"tryAGI/AI21","owner":"tryAGI","description":"Generated C# SDK based on official AI21 OpenAPI specification","archived":false,"fork":false,"pushed_at":"2024-10-24T18:30:22.000Z","size":517,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-25T01:34:02.432Z","etag":null,"topics":["ai","ai21","ai21labs","api","csharp","dotnet","generated","langchain","langchain-dotnet","llm","llms","net","net6","nswag","openapi","sdk","swagger"],"latest_commit_sha":null,"homepage":"https://tryagi.github.io/AI21/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tryAGI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"HavenDV","patreon":"havendv","ko_fi":"havendv","custom":["https://www.paypal.me/havendv","https://www.buymeacoffee.com/havendv","https://donate.stripe.com/00gfZ19zkeKLh1eaEE","https://www.upwork.com/freelancers/~017b1ad6f6af9cc189"]}},"created_at":"2023-07-31T23:00:30.000Z","updated_at":"2024-10-24T18:30:27.000Z","dependencies_parsed_at":"2024-05-06T16:01:56.642Z","dependency_job_id":"80cefb90-c20a-4a8c-87c9-5bd7a06ca1c1","html_url":"https://github.com/tryAGI/AI21","commit_stats":null,"previous_names":["tryagi/ai21"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FAI21","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FAI21/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FAI21/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FAI21/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tryAGI","download_url":"https://codeload.github.com/tryAGI/AI21/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245144975,"owners_count":20568056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai21","ai21labs","api","csharp","dotnet","generated","langchain","langchain-dotnet","llm","llms","net","net6","nswag","openapi","sdk","swagger"],"created_at":"2024-11-30T19:17:35.989Z","updated_at":"2026-04-10T22:33:14.984Z","avatar_url":"https://github.com/tryAGI.png","language":"C#","funding_links":["https://github.com/sponsors/HavenDV","https://patreon.com/havendv","https://ko-fi.com/havendv","https://www.paypal.me/havendv","https://www.buymeacoffee.com/havendv","https://donate.stripe.com/00gfZ19zkeKLh1eaEE","https://www.upwork.com/freelancers/~017b1ad6f6af9cc189"],"categories":[],"sub_categories":[],"readme":"# AI21\n\n[![Nuget package](https://img.shields.io/nuget/vpre/AI21)](https://www.nuget.org/packages/AI21/)\n[![dotnet](https://github.com/tryAGI/AI21/actions/workflows/dotnet.yml/badge.svg?branch=main)](https://github.com/tryAGI/AI21/actions/workflows/dotnet.yml)\n[![License: MIT](https://img.shields.io/github/license/tryAGI/AI21)](https://github.com/tryAGI/AI21/blob/main/LICENSE.txt)\n[![Discord](https://img.shields.io/discord/1115206893015662663?label=Discord\u0026logo=discord\u0026logoColor=white\u0026color=d82679)](https://discord.gg/Ca2xhfBf3v)\n\n## Features 🔥\n- Fully generated C# SDK based on [official OpenAPI specification](https://api.ai21.com/openapi.json) using [OpenApiGenerator](https://github.com/HavenDV/OpenApiGenerator)\n- Same day update to support new features\n- Updated and supported automatically if there are no breaking changes\n- All modern .NET features - nullability, trimming, NativeAOT, etc.\n- Support .Net Framework/.Net Standard 2.0\n- Microsoft.Extensions.AI `IChatClient` support\n\n### Usage\n```csharp\nusing AI21;\n\nusung var api = new Ai21Client(apiKey);\n\nawait api.Chat.V1J2UltraChatAsync(\n    messages:\n    [\n        new ChatMessage\n        {\n            Text = \"Hello\",\n            Role = RoleType.User,\n        }\n    ],\n    system: string.Empty,\n    cancellationToken: CancellationToken.None);\n```\n\n### Microsoft.Extensions.AI\n\nThe SDK implements [`IChatClient`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.ai.ichatclient):\n```csharp\nusing AI21;\nusing Microsoft.Extensions.AI;\n\nIChatClient chatClient = new Ai21Client(apiKey);\n\nvar response = await chatClient.GetResponseAsync(\n    [new ChatMessage(ChatRole.User, \"Hello!\")],\n    new ChatOptions { ModelId = \"jamba-1.5-mini\" });\n\nConsole.WriteLine(response.Text);\n```\n\n\u003c!-- EXAMPLES:START --\u003e\n### Chat Client Five Random Words Streaming\n```csharp\nusing var client = GetAuthorizedClient();\n\nIChatClient chatClient = client;\nvar updates = chatClient.GetStreamingResponseAsync(\n    [\n        new ChatMessage(ChatRole.User, \"Generate 5 random words.\")\n    ],\n    new ChatOptions\n    {\n        ModelId = \"jamba-large\",\n    });\n\nvar deltas = new List\u003cstring\u003e();\nawait foreach (var update in updates)\n{\n    if (!string.IsNullOrWhiteSpace(update.Text))\n    {\n        deltas.Add(update.Text);\n    }\n}\n```\n\n### Chat Client Five Random Words\n```csharp\nusing var client = GetAuthorizedClient();\n\nIChatClient chatClient = client;\nvar response = await chatClient.GetResponseAsync(\n    [\n        new ChatMessage(ChatRole.User, \"Generate 5 random words.\")\n    ],\n    new ChatOptions\n    {\n        ModelId = \"jamba-large\",\n    });\n```\n\n### Chat Client Get Service Returns Chat Client Metadata\n```csharp\nusing var client = CreateTestClient();\nIChatClient chatClient = client;\n\nvar metadata = chatClient.GetService\u003cChatClientMetadata\u003e();\n```\n\n### Chat Client Get Service Returns Null For Unknown Key\n```csharp\nusing var client = CreateTestClient();\nIChatClient chatClient = client;\n\nvar result = chatClient.GetService\u003cChatClientMetadata\u003e(serviceKey: \"unknown\");\n```\n\n### Chat Client Get Service Returns Self\n```csharp\nusing var client = CreateTestClient();\nIChatClient chatClient = client;\n\nvar self = chatClient.GetService\u003cAi21Client\u003e();\n```\n\n### Chat Client Tool Calling Multi Turn\n```csharp\nusing var client = GetAuthorizedClient();\nIChatClient chatClient = client;\n\nvar getWeatherTool = AIFunctionFactory.Create(\n    (string location) =\u003e $\"The weather in {location} is sunny, 72°F\",\n    \"GetWeather\",\n    \"Gets the current weather for a location\");\n\nvar messages = new List\u003cChatMessage\u003e\n{\n    new(ChatRole.User, \"What's the weather in Seattle?\"),\n};\n\nvar options = new ChatOptions\n{\n    ModelId = \"jamba-large\",\n    Tools = [getWeatherTool],\n};\n\n// First turn: model should call the tool\nvar response = await chatClient.GetResponseAsync(messages, options);\n\nvar functionCall = response.Messages\n    .SelectMany(m =\u003e m.Contents)\n    .OfType\u003cFunctionCallContent\u003e()\n    .FirstOrDefault();\n\n// Add assistant response with tool call and tool result\nmessages.AddRange(response.Messages);\n\nvar toolResult = await getWeatherTool.InvokeAsync(\n    functionCall!.Arguments is { } args ? new AIFunctionArguments(args) : null);\n\nmessages.Add(new ChatMessage(ChatRole.Tool,\n[\n    new FunctionResultContent(functionCall.CallId, toolResult),\n]));\n\n// Second turn: model should respond with the weather info\nvar finalResponse = await chatClient.GetResponseAsync(messages, options);\n```\n\n### Chat Client Tool Calling Single Turn\n```csharp\nusing var client = GetAuthorizedClient();\nIChatClient chatClient = client;\n\nvar getWeatherTool = AIFunctionFactory.Create(\n    (string location) =\u003e $\"The weather in {location} is sunny, 72°F\",\n    \"GetWeather\",\n    \"Gets the current weather for a location\");\n\nvar response = await chatClient.GetResponseAsync(\n    [new ChatMessage(ChatRole.User, \"What's the weather in Seattle?\")],\n    new ChatOptions\n    {\n        ModelId = \"jamba-large\",\n        Tools = [getWeatherTool],\n    });\n\nvar functionCall = response.Messages\n    .SelectMany(m =\u003e m.Contents)\n    .OfType\u003cFunctionCallContent\u003e()\n    .FirstOrDefault();\n```\n\n### Chat Client Tool Calling Streaming\n```csharp\nusing var client = GetAuthorizedClient();\nIChatClient chatClient = client;\n\nvar getWeatherTool = AIFunctionFactory.Create(\n    (string location) =\u003e $\"The weather in {location} is sunny, 72°F\",\n    \"GetWeather\",\n    \"Gets the current weather for a location\");\n\nvar updates = chatClient.GetStreamingResponseAsync(\n    [new ChatMessage(ChatRole.User, \"What's the weather in Seattle?\")],\n    new ChatOptions\n    {\n        ModelId = \"jamba-large\",\n        Tools = [getWeatherTool],\n    });\n\nvar functionCalls = new List\u003cFunctionCallContent\u003e();\nawait foreach (var update in updates)\n{\n    functionCalls.AddRange(update.Contents.OfType\u003cFunctionCallContent\u003e());\n}\n```\n\n### Test\n```csharp\nusing var api = GetAuthorizedClient();\n\n// await api.Completion.V1J2UltraCompleteAsync(\n//     messages:\n//     [\n//         new ChatMessage\n//         {\n//             Text = \"Hello\",\n//             Role = RoleType.User,\n//         }\n//     ],\n//     system: string.Empty,\n//     cancellationToken: CancellationToken.None);\n```\n\u003c!-- EXAMPLES:END --\u003e\n\n## Support\n\nPriority place for bugs: https://github.com/tryAGI/AI21/issues  \nPriority place for ideas and general questions: https://github.com/tryAGI/AI21/discussions  \nDiscord: https://discord.gg/Ca2xhfBf3v  \n\n## Acknowledgments\n\n![JetBrains logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png)\n\nThis project is supported by JetBrains through the [Open Source Support Program](https://jb.gg/OpenSourceSupport).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftryagi%2Fai21","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftryagi%2Fai21","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftryagi%2Fai21/lists"}