Model or dataset
betalgo/openai avatar
betalgo/openai

Betalgo.Ranul.OpenAI: a .NET client for the OpenAI API after the package rename

.NET library for the OpenAI service API by Betalgo Ranul

3,023 stars538 forksC#MIT

At a glance

What is it?
The community C# library for OpenAI's API has moved from Betalgo.OpenAI to Betalgo.Ranul.OpenAI and is splitting its request and response models into a Contracts project. The README is honest that not every method is tested or documented, so treat it as a working client rather than a finished SDK.
Who is it for?
Teams already writing C# against the OpenAI API and willing to track a community project's breaking changes can use Betalgo.Ranul.OpenAI, especially if they need chat completions, image generation or the Realtime API from .NET code. Teams that want a vendor-backed SDK with a documented compatibility promise should not start here.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 178 days ago.
What is it written in?
Mainly C#, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What Betalgo.Ranul.OpenAI is for

This is a community-maintained .NET library that wraps the OpenAI HTTP API so C# code can call it without hand-rolling request and response types. The README describes it as "A .NET Library for accessing OpenAI's API, provided as a community library." The repository topics list azure-openai, chatgpt, dall-e, whisper and dotnet, which maps to the surface area the project targets: chat completions, image generation, speech, and Azure-hosted OpenAI deployments.

The audience is .NET developers who already have an application in C# and want OpenAI calls inside it. It is not a Python-first tool, it is not a CLI, and it does not try to be a model runtime. If your stack is ASP.NET Core, the dependency injection path in the README is the intended entry point. If your stack is something else, the library has nothing to offer you.

One thing to settle before anything else: the package was renamed. The README carries the warning that Betalgo.OpenAI is now Betalgo.Ranul.OpenAI, and the namespace changed with it. Any tutorial, blog post or Stack Overflow answer written before that rename will point you at the old package ID.

The service object, dependency injection and how requests flow

The architecture is a single service facade. You construct an OpenAIService with an OpenAIOptions object holding your API key, or you register it in a DI container and resolve IOpenAIService from the provider. From there, capability-specific members hang off the service: ChatCompletion, the image service, and so on.

Requests are typed. You build a ChatCompletionCreateRequest, fill Messages with ChatMessage objects created by factory methods such as ChatMessage.FromSystem, ChatMessage.FromUser and ChatMessage.FromAssistant, and set a Model. The response object carries a Successful boolean, and on success you read Choices. That result flag is the pattern the README shows for chat, and it means error handling is a check on the response rather than a try/catch around every call.

Version 9.2.0 introduced the Betalgo.Ranul.OpenAI.Contracts project, which centralizes request and response models, enums and value types. The changelog is explicit that this is "the first step of a gradual migration" and that changes "may evolve after testing." The practical consequence is that the type system is moving underneath you. Legacy image request models such as CreateImageRequest were replaced with Contracts equivalents, VoiceEnum became Voice, and MessageRole was split into ChatCompletionRole and AssistantMessageRole. If you are on 9.1.x and upgrade, expect compiler errors rather than silent behaviour changes, which is the better failure mode.

Installing the package and making a first chat call

The README gives the install command for the core library. Note the package ID: this is the renamed package, not the old Betalgo.OpenAI.

shell
Install-Package Betalgo.Ranul.OpenAI

There is also an experimental utilities package, installed the same way with the ID Betalgo.OpenAI.Utilities. The README labels it experimental, so treat anything you pull from it accordingly.

Without a DI container, the README constructs the service directly and reads the key from an environment variable:

csharp
var openAIService = new OpenAIService(new OpenAIOptions()
{
    ApiKey = Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY")
});

With dependency injection, the README shows configuration in secrets.json under the key OpenAIServiceOptions, with ApiKey, an optional Organization, and an optional UseBeta flag. Registration is one line in Program.cs, either parameterless or with a settings callback that sets the API key. After that you resolve IOpenAIService from the service provider. A default model is optional and set through openAiService.SetDefaultModelId(Models.Gpt_4o).

A first real call is the chat completion sample. You pass a list of messages and a model, then check completionResult.Successful before reading completionResult.Choices.First().Message.Content. The README's example uses Models.Gpt_4o and a four-message conversation ending with a follow-up question. If the call fails, Successful is false and the choices list is not where you should be looking.

One warning worth repeating: the repository ships an OpenAI.Playground sample project, and the README states that some test methods "may result in unintended consequences such as file deletion or fine-tuning" and recommends using a separate account. That is not a hypothetical caveat, it is a direct instruction from the maintainer.

Where the library is thin, and when it is the wrong choice

The README says it plainly: "Due to time constraints, not all methods have been thoroughly tested or fully documented." That sentence should shape how you adopt this. The project is a community effort with a single named maintainer, and the documentation lives in a wiki rather than in the repository, including a Feature Availability table and a Migration Guide for breaking changes. If an endpoint you need is not in that table, you are on your own.

The version history supports a cautious reading. Three releases landed in 2025: v9.0.3 in April, then v9.0.4 and v9.1.0 on the same day in July. The changelog then documents 9.2.0 and 9.2.4, with 9.2.0 described as a gradual migration that may evolve after testing. Frequent breaking type changes are the cost of a library that tracks a fast-moving upstream API.

There is also a licensing and liability note in the README: the maintainer states he "cannot accept responsibility for any damage caused by using the library." The repository ships under MIT, which is permissive, but the disclaimer is a signal about the support expectations you should carry in.

This is the wrong tool if you need a vendor-supported SDK with a compatibility guarantee, if your team cannot absorb a namespace and type migration mid-project, or if you are not on .NET at all. It is also a poor fit if you want the library to manage file and model lifecycle for you on a production account, given the playground warning about deletions.

How it compares with the official OpenAI .NET SDK

The obvious alternative is the official OpenAI .NET SDK, which OpenAI maintains itself. The difference is not in the endpoints, both speak the same HTTP API. It is in who owns the compatibility surface.

With the official SDK, the API shape is decided by the vendor, and you get a support relationship with the company running the service. With Betalgo.Ranul.OpenAI, the shape is decided by a community maintainer who is reacting to upstream changes, and the migration guides in the wiki exist precisely because those reactions break code. The 9.2.0 Contracts project, which moves request and response models into a separate assembly, is the clearest example: it is a structural change made for internal cleanliness, and it lands on consumers as renamed enums and replaced request types.

Where this library can still be the better pick is coverage of newer surfaces. The README links a Realtime API page in the wiki and marks it as new, and the project tracks Azure OpenAI deployments through its topics and configuration. If you are already invested in this library's idioms, particularly the Successful flag and the response wrapper types, switching means rewriting call sites, not just changing a package reference.

Maintenance, upgrades and the licence

The repository is not archived, and the last push was on 2026-03-21. The most recent tagged release in the list is v9.1.0 from 2025-07-11, while the changelog in the README documents 9.2.0 and 9.2.4, which suggests the changelog is ahead of the release list you can see. Either way, the gap between the last push and the last tagged release is something to check yourself on NuGet before you pin a version.

Upgrade cost is real and asymmetric. The 9.1.0 changes were additive in places, adding a UsageModel for image generation token tracking and extending FunctionParameters with JSON Schema keywords. The 9.2.0 changes were not additive: request models were replaced, enums were renamed, and a new Contracts assembly appeared. The README points to a dedicated Contracts Upgrade Guide for that release and to a Migration Guide for breaking changes generally. Budget for reading both before you touch the package version in a project that is already in production.

The licence is MIT. That permits commercial use and modification, and it comes with no warranty. Nothing here is legal advice, so if your organisation has rules about community dependencies in regulated code paths, route it through whoever normally reviews that. The README's disclaimer about damage is consistent with what MIT already says, but the maintainer chose to repeat it, which tells you how much support to expect.

Editorial conclusion

Teams already writing C# against the OpenAI API and willing to track a community project's breaking changes can use Betalgo.Ranul.OpenAI, especially if they need chat completions, image generation or the Realtime API from .NET code. Teams that want a vendor-backed SDK with a documented compatibility promise should not start here. Before adopting, verify that the package ID on NuGet is Betalgo.Ranul.OpenAI rather than the older Betalgo.OpenAI, read the Migration Guides for breaking changes and the Contracts Upgrade Guide for 9.2.0, and check the Feature Availability table for the specific endpoints you depend on.

Frequently asked questions

How do I use the OpenAI API from C# with Betalgo.Ranul.OpenAI?

Install the package with Install-Package Betalgo.Ranul.OpenAI, then either construct an OpenAIService with an OpenAIOptions holding your ApiKey, or register it with serviceCollection.AddOpenAIService() and resolve IOpenAIService. Calls are typed: you build a ChatCompletionCreateRequest with a Messages list and a Model, then check the Successful flag on the result before reading Choices.

How do I use my OpenAI API key with Betalgo.Ranul.OpenAI?

The README shows the key passed through OpenAIOptions.ApiKey, either read from an environment variable or set in a settings callback during dependency injection registration. For DI setups it recommends user secrets, with the configuration section named OpenAIServiceOptions and an optional Organization field. The README links to the OpenAI platform pages for obtaining the key and the organization ID.

Why did the Betalgo.OpenAI package name change to Betalgo.Ranul.OpenAI?

The README states that Betalgo.OpenAI is now Betalgo.Ranul.OpenAI and that the namespace changed as well. It does not give a reason for the rename. The practical effect is that older tutorials and answers referencing the previous package ID and namespace will not match the current install command.

How do I use OpenAI Whisper with Betalgo.Ranul.OpenAI?

Whisper appears in the repository topics alongside chatgpt, dall-e and azure-openai, so audio transcription is part of the surface area the project targets. The README does not include a Whisper code sample, and it points to the wiki for detailed documentation, so check the Feature Availability table there before assuming a specific transcription method exists.

Does Betalgo.Ranul.OpenAI work with Azure OpenAI?

Azure OpenAI is one of the repository topics, and the README's configuration sample includes an optional Organization field alongside the API key. The README does not document the Azure-specific setup steps in the text available here, so consult the wiki pages linked from the README before wiring it to an Azure deployment.

Official sources

  1. betalgo/openai on GitHub
  2. License: MIT
  3. Project website
  4. README
  5. Releases
Community notes

Community notes