A simple C# / .NET library to use with OpenAI's API, including GPT-4, GPT-3.5-turbo, GPT-3.5-instruct, DALL·E, etc. Supports commercial and self hosted API providers such as OpenAI, Azure OpenAI, KoboldCpp, AI Horde and others. Formerly a fork of Open-AI-Dotnet, hard-forked due to extensive changes and stale upstream.
$ dotnet add package OpenAiNgOpenAiNextGeneration is a simple .NET library to use with various OpenAI compatible providers, such
as OpenAI, Azure OpenAI,
and KoboldCpp (
v1.45.2+). Supports features such as function calling in conjunction with streaming, caches its own HttpClients.
Supported features compared to OpenAI-API-dotnet:
Features scheduled for open-sourcing:
Install the library via NuGet:
Install-Package OpenAiNg
var api = new OpenAiNg.OpenAiApi("YOUR_API_KEY");
var result = await api.Completions.GetCompletion("One Two Three One Two");
Console.WriteLine(result);
// should print something starting with "Three"
Unlike the original library, OpenAiNg supports only .NET Core >= 6.0, if you need .NET Standard 2.0 /.NET Framework support, please use OpenAI-API-DotNet.
Install package OpenAiNg from Nuget. Here's how via the command line:
Install-Package OpenAiNg
Pass keys directly to ApiAuthentication(string key) constructor.
You use the APIAuthentication when you initialize the API as shown:
// for example
var api = new OpenAiApi("YOUR_API_KEY"); // shorthand
// or
var api = new OpenAiApi(new APIAuthentication("YOUR_API_KEY")); // create object manually
You may optionally include an OpenAi Organization if multiple Organizations are under one account.
// for example
var api = new OpenAiApi(new ApiAuthentication("YOUR_API_KEY", "org-yourOrgHere"));
Every single class, method, and property has extensive XML documentation, so it should show up automatically in IntelliSense. That combined with the official OpenAI documentation should be enough to get started. Feel free to open an issue here if you have any questions.
This library is licensed under MIT license.