AzureOpenAIClient 1.0.0

.NET Standard 2.1
There is a newer version of this package available.
See the version list below for details.
dotnet add package AzureOpenAIClient --version 1.0.0
NuGet\Install-Package AzureOpenAIClient -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="AzureOpenAIClient" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AzureOpenAIClient --version 1.0.0
#r "nuget: AzureOpenAIClient, 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.
// Install AzureOpenAIClient as a Cake Addin
#addin nuget:?package=AzureOpenAIClient&version=1.0.0

// Install AzureOpenAIClient as a Cake Tool
#tool nuget:?package=AzureOpenAIClient&version=1.0.0

Azure OpenAI .NET Client

This project contains an implementation of a pre-configured injectable OpenAIClient which can be used to communicate to the Azure OpenAI platform instead of relying purely on hand-crafted REST API calls.

OpenAIClient settings

The following settings allow the OpenAI client to connect to your Azure resource, authenticate, and work with the right deployment model you've created in the portal.

Setting Purpose Example
BaseUri The fully qualified domain name of the OpenAI resource in Azure.
ApiKey The API key used to authenticate the client to OpenAI in Azure. 1bbcc11a3a233857zz12aa5f2fake99af7d9c
DeploymentName The name of the deployment for a given OpenAI model. text-davinci-002
ApiVersion The API version for your OpenAI resource. 2022-12-01


The section below shows an example JSON configuration which can be stored in your secrets.json file, appsettings.development.json, or appsettings.json.

"OpenAiClientConfiguration": {
    "BaseUri": "[your_fqdn]",
    "ApiKey": "[your_api_key]",
    "DeploymentName": "[your_deployment_name]",
    "ApiVersion": "[supported_api_version]"

Setup in Program.cs

In your .NET application, you can use the NuGet package to allow for the following extension method which will register a singleton reference of the OpenAIClient instance.

builder.Services.AddOpenAIClient(x => builder.Configuration.Bind(nameof(OpenAIClientConfiguration), x));

OpenAIClient usage

Since the OpenAIClient is registered for Dependency Injection, you can inject it and use it with the GetTextCompletionResponseAsync() method. The CompletionResponse contains the model OpenAI uses with their typical REST API.

public class MyClass
    private readonly OpenAIClient _client;

    public MyClass(OpenAIClient client)
        _client = client;

    Task DoWork(string input)
        var completionRequest = new CompletionRequest()
                Prompt = input,
                MaxTokens = 100
        CompletionResponse? completionResponse = await _openAiClient.GetTextCompletionResponseAsync(completionRequest);            
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AzureOpenAIClient:

Package Downloads

Bootstrap Blazor OCR/AiForm/Translate components

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 204 2/14/2023
1.0.1 122 2/7/2023
1.0.0 243 2/1/2023
1.0.0-beta1 62 2/1/2023

Initial release.