openai-dotnet

The official .NET library for the OpenAI API

What is openai-dotnet?

The official .NET library for the OpenAI API

Overview of openai-dotnet

What it is

The OpenAI .NET library is the official .NET client for the OpenAI REST API. It is generated from the OpenAI OpenAPI specification in collaboration with Microsoft and provides convenient access to OpenAI services from .NET applications. The library is compatible with all .NET Standard 2.0 applications.

Key features

  • Provides async and sync client methods for all major OpenAI API endpoints (chat, audio, images, embeddings, assistants, etc.)
  • Supports streaming chat completions, tool/function calling, structured outputs, and audio in chat - Includes built-in support for dependency injection in ASP.NET Core applications - Allows custom base URLs and API keys for connecting to alternative endpoints or self-hosted models - Offers an OpenAIClient class that can create and share configuration across multiple feature-area clients - Thread-safe clients can be registered as singletons for resource efficiency

Use cases

  • Building .NET applications that integrate OpenAI chat, audio transcription, image generation, or text embeddings - Creating assistants with retrieval augmented generation (RAG), file search, or web search capabilities - Implementing streaming responses, function calling, and structured outputs in conversational AI - Working with Azure OpenAI deployments using the same client library - Developing decision-making, moderation, fine-tuning, and evaluation workflows

Getting started

cli dotnet add package OpenAI After installing the package, create a client with your API key: C# ChatClient client = new(model: “gpt-5.1”, apiKey: Environment.GetEnvironmentVariable(“OPENAI_API_KEY”)); ChatCompletion completion = client.CompleteChat(“Say ‘this is a test.’”); Console.WriteLine($”[ASSISTANT]: {completion.Content[0].Text}”);

License and pricing

The library is licensed under the MIT license. Pricing for the OpenAI API is not covered in this repository; see OpenAI’s website for pricing details.

這是什麼

OpenAI .NET 程式庫是 OpenAI REST API 的官方 .NET 用戶端。它與 Microsoft 合作,根據 OpenAI OpenAPI 規格生成,為 .NET 應用程式提供方便的 OpenAI 服務存取。此程式庫相容於所有 .NET Standard 2.0 應用程式。

主要功能

  • 為所有主要 OpenAI API 端點(聊天、音訊、圖片、嵌入、助手等)提供非同步與同步用戶端方法 - 支援串流聊天完成、工具/函式呼叫、結構化輸出以及聊天中的音訊 - 內建 ASP.NET Core 應用程式的相依性注入支援 - 允許自訂基礎 URL 和 API 金鑰,以連接到替代端點或自託管模型 - 提供 OpenAIClient 類別,可建立並跨多個功能區域用戶端共享設定 - 執行緒安全的用戶端可註冊為單例,以提升資源效率

使用情境

  • 建置整合 OpenAI 聊天、音訊轉錄、圖片生成或文字嵌入的 .NET 應用程式 - 建立具備檢索增強生成(RAG)、檔案搜尋或網路搜尋能力的助手 - 在對話式 AI 中實作串流回應、函式呼叫與結構化輸出 - 使用相同的用戶端程式庫處理 Azure OpenAI 部署 - 開發決策制定、內容審核、微調與評估工作流程

快速開始

cli dotnet add package OpenAI 安裝套件後,使用您的 API 金鑰建立用戶端: C# ChatClient client = new(model: “gpt-5.1”, apiKey: Environment.GetEnvironmentVariable(“OPENAI_API_KEY”)); ChatCompletion completion = client.CompleteChat(“Say ‘this is a test.’”); Console.WriteLine($”[ASSISTANT]: {completion.Content[0].Text}”);

授權與價格

此程式庫採用 MIT 授權。OpenAI API 的價格未涵蓋在此儲存庫中;請參閱 OpenAI 網站了解價格詳情。

Based on the project's public README and repository metadata.

Add this badge to your README

Featured on YunoDB Badge styles & help

Maintain this project? Show that it is featured on YunoDB.

Markdown[![Featured on YunoDB](https://yunodb.com/badge/openaiopenai-dotnet.svg)](https://yunodb.com/tools/openaiopenai-dotnet?utm_source=github&utm_medium=badge)
HTML<a href="https://yunodb.com/tools/openaiopenai-dotnet?utm_source=github&utm_medium=badge"><img src="https://yunodb.com/badge/openaiopenai-dotnet.svg" alt="Featured on YunoDB" height="20"></a>