The OpenAI .NET library exposes the OpenAI REST API to .NET apps via NuGet, with clients for chat, audio, images, embeddings, assistants, and related API areas.
Overview
The OpenAI .NET API library provides typed access to the OpenAI REST API from .NET applications. It is generated from the OpenAPI specification in collaboration with Microsoft and installs as a NuGet package for .NET Standard 2.0 and newer targets.
The API is split into namespaces and client classes that mirror REST feature areas, including chat completions, responses, audio, images, embeddings, files, batches, fine-tuning, moderations, vector stores, assistants, realtime, and decisions. A shared OpenAIClient can create multiple feature clients with common credentials. Sync and async methods are paired across clients.
Documentation covers streaming chat, tool and function calling, structured outputs, audio in chat, RAG with assistants, Azure OpenAI, dependency injection in ASP.NET Core, retries, observability, and custom base URLs for OpenAI-compatible endpoints. Some APIs remain marked experimental in .NET until stabilized.
Key features
- NuGet package for .NET applications
- Chat completions with streaming
- Tools and function calling support
- Structured output response formats
- Audio, image, and embedding clients
- Assistants and vector store APIs
- Azure OpenAI configuration paths
- ASP.NET Core dependency injection
Use cases
- Calling OpenAI APIs from C# or F# apps
- Building chat features with streaming
- Server apps using injected OpenAI clients
- Proxies to OpenAI-compatible LLM endpoints
- Embeddings and image generation in .NET