ForeverTools.OpenAI 1.0.0

dotnet add package ForeverTools.OpenAI --version 1.0.0
                    
NuGet\Install-Package ForeverTools.OpenAI -Version 1.0.0
                    
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="ForeverTools.OpenAI" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ForeverTools.OpenAI" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ForeverTools.OpenAI" />
                    
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 ForeverTools.OpenAI --version 1.0.0
                    
#r "nuget: ForeverTools.OpenAI, 1.0.0"
                    
#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 ForeverTools.OpenAI@1.0.0
                    
#: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=ForeverTools.OpenAI&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ForeverTools.OpenAI&version=1.0.0
                    
Install as a Cake Tool

ForeverTools.OpenAI

A clean, dependency-injection-ready .NET wrapper for the OpenAI API — chat completions, embeddings, and image generation in one simple client.

Features

  • Chat Completions — simple one-shot, multi-turn, and streaming
  • Embeddings — single and batch embedding generation for RAG and semantic search
  • Image Generation — DALL-E 3 and DALL-E 2, multiple sizes
  • Dependency Injection — built-in IServiceCollection extensions
  • Multi-targeting — .NET 8.0, .NET 6.0, .NET Standard 2.0
  • Full async/await with cancellation token support

Installation

dotnet add package ForeverTools.OpenAI

Quick Start

Get your API key at platform.openai.com/api-keys.

using ForeverTools.OpenAI;

var client = new OpenAiClient("your-api-key");

// Chat completion
var reply = await client.ChatAsync("What is the capital of France?");
Console.WriteLine(reply); // "The capital of France is Paris."

// Streaming
await foreach (var chunk in client.StreamChatAsync("Tell me a joke"))
    Console.Write(chunk);

// Embeddings (for RAG / semantic search)
var vector = await client.EmbedAsync("Hello world");
Console.WriteLine($"Dimension: {vector.Length}"); // 1536

// Image generation
var url = await client.GenerateImageAsync("A sunset over mountains");
Console.WriteLine(url);

Dependency Injection

// Program.cs
builder.Services.AddForeverToolsOpenAI("your-api-key");

// Or from configuration
builder.Services.AddForeverToolsOpenAI(builder.Configuration);
// appsettings.json
{
  "OpenAI": {
    "ApiKey": "your-api-key",
    "DefaultChatModel": "gpt-4o-mini",
    "DefaultImageModel": "dall-e-3",
    "DefaultEmbeddingModel": "text-embedding-3-small"
  }
}

Then inject OpenAiClient directly:

public class MyService(OpenAiClient ai)
{
    public Task<string> SummarizeAsync(string text) =>
        ai.ChatAsync($"Summarise this in one sentence: {text}");
}

Available Models

// Chat
OpenAiModels.Chat.Gpt4o          // gpt-4o
OpenAiModels.Chat.Gpt4oMini      // gpt-4o-mini (default)
OpenAiModels.Chat.Gpt4Turbo      // gpt-4-turbo
OpenAiModels.Chat.O3Mini         // o3-mini

// Images
OpenAiModels.Image.DallE3        // dall-e-3 (default)
OpenAiModels.Image.DallE2        // dall-e-2

// Embeddings
OpenAiModels.Embedding.TextEmbedding3Small  // default
OpenAiModels.Embedding.TextEmbedding3Large

Multi-turn Conversations

using OpenAI.Chat;

var messages = new List<ChatMessage>
{
    new SystemChatMessage("You are a helpful assistant."),
    new UserChatMessage("What is 2 + 2?"),
    new AssistantChatMessage("4"),
    new UserChatMessage("And multiply by 3?"),
};

var reply = await client.ChatAsync(messages);
Console.WriteLine(reply); // "12"

Advanced: Direct Client Access

For features not covered by this wrapper, access the underlying OpenAI.OpenAIClient:

var underlying = client.UnderlyingClient;
var audioClient = underlying.GetAudioClient("whisper-1");

Other ForeverTools Packages

Package Description
ForeverTools.AIML 400+ models via AI/ML API (GPT-4, Claude, Llama, Gemini)
ForeverTools.ImageGen AI image generation (DALL-E, Flux, SD)
ForeverTools.Translate AI translation, 100+ languages
ForeverTools.OCR AI-powered OCR via GPT-4 Vision

Need Utility APIs?

kiprio.com offers 30+ utility APIs with a free tier: email validation, DNS lookup, WHOIS, SSL checks, IP geolocation, OCR, QR codes, screenshots, sentiment analysis, translation, grammar checking, and more.

pip install kiprio   # Python SDK
dotnet add package ForeverTools.OpenAI   # .NET SDK (this package)

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.0.0 79 4/28/2026