Azure OpenAI — .NET SDK Quick Reference
Condensed from azure-ai-openai-dotnet. Full patterns (function calling, structured outputs, RAG with Search) in the azure-ai-openai-dotnet plugin skill if installed.
Install
dotnet add package Azure.AI.OpenAIQuick Start
using Azure.AI.OpenAI;
using OpenAI.Chat;
var azureClient = new AzureOpenAIClient(new Uri(endpoint), credential);
ChatClient chatClient = azureClient.GetChatClient("gpt-4o-mini");Non-Obvious Patterns
- Client hierarchy:
AzureOpenAIClient.GetChatClient()/GetEmbeddingClient()/GetImageClient()/GetAudioClient() - Reasoning models (o1): use
DeveloperChatMessageinstead ofSystemChatMessage, setReasoningEffortLevel - RAG:
#pragma warning disable AOAI001thenoptions.AddDataSource(new AzureSearchChatDataSource{...}) - Structured outputs:
ChatResponseFormat.CreateJsonSchemaFormat(...)
Best Practices
- Use Entra ID in production — avoid API keys
- Reuse client instances — create once, share across requests
- Handle rate limits — implement exponential backoff for 429 errors
- Stream for long responses — use
CompleteChatStreamingAsync - Set appropriate timeouts for long completions
- Use structured outputs for consistent response format
- Monitor token usage via
completion.Usagefor cost management - Validate tool call arguments before execution