![]() |
VOOZH | about |
dotnet add package Microsoft.Extensions.AI.AzureAIInference --version 10.0.0-preview.1.25559.3
NuGet\Install-Package Microsoft.Extensions.AI.AzureAIInference -Version 10.0.0-preview.1.25559.3
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="10.0.0-preview.1.25559.3" />
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="10.0.0-preview.1.25559.3" />Directory.Packages.props
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" />Project file
paket add Microsoft.Extensions.AI.AzureAIInference --version 10.0.0-preview.1.25559.3
#r "nuget: Microsoft.Extensions.AI.AzureAIInference, 10.0.0-preview.1.25559.3"
#:package Microsoft.Extensions.AI.AzureAIInference@10.0.0-preview.1.25559.3
#addin nuget:?package=Microsoft.Extensions.AI.AzureAIInference&version=10.0.0-preview.1.25559.3&prereleaseInstall as a Cake Addin
#tool nuget:?package=Microsoft.Extensions.AI.AzureAIInference&version=10.0.0-preview.1.25559.3&prereleaseInstall as a Cake Tool
Provides an implementation of the IChatClient interface for the Azure.AI.Inference package.
From the command-line:
dotnet add package Microsoft.Extensions.AI.AzureAIInference
Or directly in the C# project file:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="[CURRENTVERSION]" />
</ItemGroup>
using Azure;
using Microsoft.Extensions.AI;
IChatClient client =
new Azure.AI.Inference.ChatCompletionsClient(
new("https://models.inference.ai.azure.com"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("GH_TOKEN")!))
.AsIChatClient("gpt-4o-mini");
Console.WriteLine(await client.GetResponseAsync("What is AI?"));
Note: When connecting with Azure Open AI, the URL passed into the
ChatCompletionsClientneeds to includeopenai/deployments/{yourDeployment}. For example:new Azure.AI.Inference.ChatCompletionsClient( new("https://{your-resource-name}.openai.azure.com/openai/deployments/{yourDeployment}"), new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY")!))
using Azure;
using Microsoft.Extensions.AI;
IChatClient client =
new Azure.AI.Inference.ChatCompletionsClient(
new("https://models.inference.ai.azure.com"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("GH_TOKEN")!))
.AsIChatClient("gpt-4o-mini");
Console.WriteLine(await client.GetResponseAsync(
[
new ChatMessage(ChatRole.System, "You are a helpful AI assistant"),
new ChatMessage(ChatRole.User, "What is AI?"),
]));
using Azure;
using Microsoft.Extensions.AI;
IChatClient client =
new Azure.AI.Inference.ChatCompletionsClient(
new("https://models.inference.ai.azure.com"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("GH_TOKEN")!))
.AsIChatClient("gpt-4o-mini");
await foreach (var update in client.GetStreamingResponseAsync("What is AI?"))
{
Console.Write(update);
}
using System.ComponentModel;
using Azure;
using Microsoft.Extensions.AI;
IChatClient azureClient =
new Azure.AI.Inference.ChatCompletionsClient(
new("https://models.inference.ai.azure.com"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("GH_TOKEN")!))
.AsIChatClient("gpt-4o-mini");
IChatClient client = new ChatClientBuilder(azureClient)
.UseFunctionInvocation()
.Build();
ChatOptions chatOptions = new()
{
Tools = [AIFunctionFactory.Create(GetWeather)]
};
await foreach (var message in client.GetStreamingResponseAsync("Do I need an umbrella?", chatOptions))
{
Console.Write(message);
}
[Description("Gets the weather")]
static string GetWeather() => Random.Shared.NextDouble() > 0.5 ? "It's sunny" : "It's raining";
using Azure;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
IDistributedCache cache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()));
IChatClient azureClient =
new Azure.AI.Inference.ChatCompletionsClient(
new("https://models.inference.ai.azure.com"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("GH_TOKEN")!))
.AsIChatClient("gpt-4o-mini");
IChatClient client = new ChatClientBuilder(azureClient)
.UseDistributedCache(cache)
.Build();
for (int i = 0; i < 3; i++)
{
await foreach (var message in client.GetStreamingResponseAsync("In less than 100 words, what is AI?"))
{
Console.Write(message);
}
Console.WriteLine();
Console.WriteLine();
}
using Azure;
using Microsoft.Extensions.AI;
using OpenTelemetry.Trace;
// Configure OpenTelemetry exporter
var sourceName = Guid.NewGuid().ToString();
var tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
.AddSource(sourceName)
.AddConsoleExporter()
.Build();
IChatClient azureClient =
new Azure.AI.Inference.ChatCompletionsClient(
new("https://models.inference.ai.azure.com"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("GH_TOKEN")!))
.AsIChatClient("gpt-4o-mini");
IChatClient client = new ChatClientBuilder(azureClient)
.UseOpenTelemetry(sourceName: sourceName, configure: c => c.EnableSensitiveData = true)
.Build();
Console.WriteLine(await client.GetResponseAsync("What is AI?"));
using System.ComponentModel;
using Azure;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using OpenTelemetry.Trace;
// Configure telemetry
var sourceName = Guid.NewGuid().ToString();
var tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
.AddSource(sourceName)
.AddConsoleExporter()
.Build();
// Configure caching
IDistributedCache cache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()));
// Configure tool calling
var chatOptions = new ChatOptions
{
Tools = [AIFunctionFactory.Create(GetPersonAge)]
};
IChatClient azureClient =
new Azure.AI.Inference.ChatCompletionsClient(
new("https://models.inference.ai.azure.com"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("GH_TOKEN")!))
.AsIChatClient("gpt-4o-mini");
IChatClient client = new ChatClientBuilder(azureClient)
.UseDistributedCache(cache)
.UseFunctionInvocation()
.UseOpenTelemetry(sourceName: sourceName, configure: c => c.EnableSensitiveData = true)
.Build();
for (int i = 0; i < 3; i++)
{
Console.WriteLine(await client.GetResponseAsync("How much older is Alice than Bob?", chatOptions));
}
[Description("Gets the age of a person specified by name.")]
static int GetPersonAge(string personName) =>
personName switch
{
"Alice" => 42,
"Bob" => 35,
_ => 26,
};
using Azure;
using Azure.AI.Inference;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
// App Setup
var builder = Host.CreateApplicationBuilder();
builder.Services.AddSingleton(
new ChatCompletionsClient(
new("https://models.inference.ai.azure.com"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("GH_TOKEN")!)));
builder.Services.AddDistributedMemoryCache();
builder.Services.AddLogging(b => b.AddConsole().SetMinimumLevel(LogLevel.Trace));
builder.Services.AddChatClient(services => services.GetRequiredService<ChatCompletionsClient>().AsIChatClient("gpt-4o-mini"))
.UseDistributedCache()
.UseLogging();
var app = builder.Build();
// Elsewhere in the app
var chatClient = app.Services.GetRequiredService<IChatClient>();
Console.WriteLine(await chatClient.GetResponseAsync("What is AI?"));
using Azure;
using Azure.AI.Inference;
using Microsoft.Extensions.AI;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton(new ChatCompletionsClient(
new("https://models.inference.ai.azure.com"),
new AzureKeyCredential(builder.Configuration["GH_TOKEN"]!)));
builder.Services.AddChatClient(services =>
services.GetRequiredService<ChatCompletionsClient>().AsIChatClient("gpt-4o-mini"));
var app = builder.Build();
app.MapPost("/chat", async (IChatClient client, string message) =>
{
var response = await client.GetResponseAsync(message);
return response.Message;
});
app.Run();
Refer to the Microsoft.Extensions.AI libraries documentation for more information and API usage examples.
We welcome feedback and contributions in our GitHub repo.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 is compatible. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Microsoft.Extensions.AI.AzureAIInference:
| Package | Downloads |
|---|---|
|
Microsoft.SemanticKernel.Connectors.AzureAIInference
Semantic Kernel Model as a Service connectors for Azure AI Studio. Contains clients for chat completion, embeddings and text to image generation. |
|
|
Aspire.Azure.AI.Inference
A client for Azure AI Inference SDK that integrates with Aspire, including logging and telemetry. |
|
|
Jumoo.TranslationManager.AI
AI Connectors for Jumoo Translation Manager |
|
|
Devlooped.Extensions.AI
Extensions for Microsoft.Extensions.AI |
|
|
CToolkit.Microsoft.Extensions.AI
Alpha-Version of the WinForms AI- and Modernization-Toolkit. You need to target TFM 'net9-windows10.0.22000.0' at the least: NET 9+ and Windows version 10.0.22000.0 or higher. Use on own risk - this is a personal Hobby project, provided without support neither from Microsoft nor from the Authors. |
Showing the top 8 popular GitHub repositories that depend on Microsoft.Extensions.AI.AzureAIInference:
| Repository | Stars |
|---|---|
|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
|
microsoft/aspire
Aspire is the tool for code-first, extensible, observable dev and deploy.
|
|
|
bitfoundation/bitplatform
Build all of your apps using what you already know and love ❤️
|
|
|
getcellm/cellm
Use LLMs in Excel formulas
|
|
| dotnet/ai-samples | |
|
rwjdk/MicrosoftAgentFrameworkSamples
Samples demonstrating the Microsoft Agent Framework in C#
|
|
|
Azure-Samples/eShopLite
eShopLite is a set of reference .NET applications implementing an eCommerce site with features like Semantic Search, MCP, Reasoning models and more.
|
|
|
csharpfritz/Fritz.StreamTools
Handy tools for managing my live stream, built with ASP.NET Core
|
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0-preview.1.25559.3 | 290,323 | 11/11/2025 |
| 9.10.0-preview.1.25513.3 | 48,351 | 10/14/2025 |
| 9.9.1-preview.1.25474.6 | 39,170 | 9/25/2025 |
| 9.9.0-preview.1.25458.4 | 58,295 | 9/9/2025 |
| 9.8.0-preview.1.25412.6 | 54,049 | 8/12/2025 |
| 9.7.1-preview.1.25365.4 | 146,567 | 7/15/2025 |
| 9.7.0-preview.1.25356.2 | 4,086 | 7/8/2025 |
| 9.6.0-preview.1.25310.2 | 19,290 | 6/10/2025 |
| 9.5.0-preview.1.25265.7 | 76,611 | 5/16/2025 |
| 9.5.0-preview.1.25262.9 | 5,023 | 5/13/2025 |
| 9.4.4-preview.1.25259.16 | 5,365 | 5/10/2025 |
| 9.4.3-preview.1.25230.7 | 30,227 | 5/1/2025 |
| 9.4.0-preview.1.25207.5 | 51,090 | 4/8/2025 |
| 9.3.0-preview.1.25161.3 | 38,894 | 3/11/2025 |
| 9.3.0-preview.1.25114.11 | 38,204 | 2/16/2025 |
| 9.1.0-preview.1.25064.3 | 23,123 | 1/14/2025 |
| 9.0.1-preview.1.24570.5 | 50,788 | 11/21/2024 |
| 9.0.0-preview.9.24556.5 | 4,458 | 11/12/2024 |
| 9.0.0-preview.9.24525.1 | 26,753 | 10/26/2024 |
| 9.0.0-preview.9.24507.7 | 2,834 | 10/8/2024 |