Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Guidance for building and deploying AI solutions on Azure using Azure AI services and Copilot for Azure
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/sdk/azure-ai-openai-dotnet.md
1# Azure OpenAI — .NET SDK Quick Reference23> Condensed from **azure-ai-openai-dotnet**. Full patterns (function calling, structured outputs, RAG with Search)4> in the **azure-ai-openai-dotnet** plugin skill if installed.56## Install7```bash8dotnet add package Azure.AI.OpenAI9```1011## Quick Start12```csharp13using Azure.AI.OpenAI;14using OpenAI.Chat;15var azureClient = new AzureOpenAIClient(new Uri(endpoint), credential);16ChatClient chatClient = azureClient.GetChatClient("gpt-4o-mini");17```1819## Non-Obvious Patterns20- Client hierarchy: `AzureOpenAIClient.GetChatClient()` / `GetEmbeddingClient()` / `GetImageClient()` / `GetAudioClient()`21- Reasoning models (o1): use `DeveloperChatMessage` instead of `SystemChatMessage`, set `ReasoningEffortLevel`22- RAG: `#pragma warning disable AOAI001` then `options.AddDataSource(new AzureSearchChatDataSource{...})`23- Structured outputs: `ChatResponseFormat.CreateJsonSchemaFormat(...)`2425## Best Practices261. Use Entra ID in production — avoid API keys272. Reuse client instances — create once, share across requests283. Handle rate limits — implement exponential backoff for 429 errors294. Stream for long responses — use `CompleteChatStreamingAsync`305. Set appropriate timeouts for long completions316. Use structured outputs for consistent response format327. Monitor token usage via `completion.Usage` for cost management338. Validate tool call arguments before execution34