Release Overview
Azure.AI.OpenAI 2.1.0 marks the first Generally Available (GA) release of the complete SDK rewrite. The 2.x series was built jointly with the OpenAI team and uses the OpenAI .NET client library as its foundation — Azure-specific features (deployment mapping, Azure AD auth, content filtering metadata) layer on top.
Key Features
Native Streaming with IAsyncEnumerable
Streaming chat completions now use IAsyncEnumerable<StreamingChatCompletionUpdate> — no callbacks, no event handlers:
using Azure.AI.OpenAI;
using Azure.Identity;
using OpenAI.Chat;
var client = new AzureOpenAIClient(
new Uri(configuration["AzureOpenAI:Endpoint"]!),
new DefaultAzureCredential());
ChatClient chatClient = client.GetChatClient("gpt-4o");
await foreach (StreamingChatCompletionUpdate update in
chatClient.CompleteChatStreamingAsync("Explain RAG in one paragraph"))
{
foreach (ChatMessageContentPart part in update.ContentUpdate)
{
Console.Write(part.Text);
}
}
Structured Outputs (JSON Schema Enforcement)
The response_format parameter now supports strict JSON Schema enforcement — the model is constrained to only produce valid JSON matching your schema:
ChatCompletionOptions options = new()
{
ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat(
jsonSchemaFormatName: "product_classification",
jsonSchema: BinaryData.FromBytes("""
{
"type": "object",
"properties": {
"category": { "type": "string" },
"confidence": { "type": "number" },
"tags": { "type": "array", "items": { "type": "string" } }
},
"required": ["category", "confidence", "tags"],
"additionalProperties": false
}
"""u8.ToArray()),
jsonSchemaIsStrict: true)
};
ChatCompletion completion = await chatClient.CompleteChatAsync(
[new UserChatMessage("Classify: wireless noise-cancelling headphones")],
options);
// completion.Content[0].Text is guaranteed to be valid JSON
var result = JsonSerializer.Deserialize<ProductClassification>(completion.Content[0].Text);
GPT-4 Vision (Multimodal Inputs)
Pass images alongside text in a single chat request:
ChatMessage[] messages =
[
new UserChatMessage(
ChatMessageContentPart.CreateTextPart("What is in this image?"),
ChatMessageContentPart.CreateImagePart(
imageUri: new Uri("https://example.com/diagram.png"),
imageDetailLevel: ChatImageDetailLevel.High))
];
ChatCompletion result = await chatClient.CompleteChatAsync(messages);
For local images, use BinaryData directly:
var imageData = BinaryData.FromBytes(await File.ReadAllBytesAsync("screenshot.png"));
ChatMessageContentPart.CreateImagePart(imageData, "image/png");
Azure Managed Identity Authentication
// In production: use DefaultAzureCredential for Managed Identity
var client = new AzureOpenAIClient(
new Uri(environment.GetVariable("AZURE_OPENAI_ENDPOINT")!),
new DefaultAzureCredential());
// In development: authenticates via Azure CLI / VS credentials
// No API key needed or stored
How to Install
dotnet add package Azure.AI.OpenAI --version 2.1.0
The OpenAI 2.1.0 package is automatically pulled in as a transitive dependency — you do not need to reference it separately unless you use the base OpenAI types directly.
Breaking Changes from 1.x
| 1.x | 2.x |
|---|---|
new OpenAIClient(endpoint, credential) | new AzureOpenAIClient(endpoint, credential) |
GetChatCompletionsAsync | GetChatClient("deployment").CompleteChatAsync |
ChatRequestUserMessage | new UserChatMessage(...) |
StreamingResponse<StreamingChatCompletions> | IAsyncEnumerable<StreamingChatCompletionUpdate> |
Choice.Message.Content | ChatCompletion.Content[0].Text |
Compatibility
Targets netstandard2.0 — works on .NET 8 LTS, .NET 9, .NET 10, and .NET Framework 4.7.2+.