Integrate Azure OpenAI Models into .NET Apps
The .NET client library for Azure OpenAI Service - chat, RAG, embeddings, DALL-E, and Whisper models with function calling.
Why it matters
Leverage powerful Azure OpenAI models like GPT-4, DALL-E, and Whisper directly within your .NET applications. This asset provides a client library for seamless integration, enabling advanced AI capabilities.
Outcomes
What it gets done
Generate text completions and chat responses
Create images using DALL-E
Transcribe audio using Whisper
Generate embeddings for text analysis
Integrate with Azure AI Search for RAG patterns
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-azure-ai-openai-dotnet | bash Overview
Azure.AI.OpenAI (.NET)
This skill covers the Azure.AI.OpenAI .NET SDK: chat completions with RAG and function calling, structured JSON output, embeddings, DALL-E image generation, and Whisper transcription/TTS. Use it for .NET applications calling Azure-hosted OpenAI models. Prefer Microsoft Entra ID authentication over API keys for production.
What it does
This skill covers Azure.AI.OpenAI, the .NET client library for Azure OpenAI Service (v2.1.0 stable), providing access to GPT-4, GPT-4o, embeddings, DALL-E, and Whisper models. A top-level AzureOpenAIClient exposes GetChatClient, GetEmbeddingClient, GetImageClient, GetAudioClient, and GetAssistantClient, each scoped to a specific deployment name. Two authentication paths are documented: API-key auth via AzureKeyCredential, and Microsoft Entra ID via DefaultAzureCredential (recommended for production); the OpenAI SDK itself can also be pointed at Azure directly using a BearerTokenPolicy scoped to the cognitiveservices.azure.com resource. Chat completions cover basic synchronous calls, async calls with token-usage reporting, streaming responses via CompleteChatStreamingAsync, tunable options (MaxOutputTokenCount, Temperature, TopP, frequency/presence penalties), multi-turn conversations built by appending each assistant reply back into the message list, structured JSON-Schema-constrained outputs via ChatResponseFormat.CreateJsonSchemaFormat with a strict schema, reasoning-model-specific options (ReasoningEffortLevel, larger MaxOutputTokenCount, DeveloperChatMessage) for o1/o4-mini-class models, retrieval-augmented generation by attaching an AzureSearchChatDataSource to chat options and reading back intent and citations from the response's message context, and function/tool calling by defining a ChatTool with a JSON-Schema parameter definition and inspecting ToolCalls when FinishReason is ToolCalls. Beyond chat, it covers single and batch embedding generation (GenerateEmbeddingAsync / GenerateEmbeddingsAsync, reading back float vectors), DALL-E image generation with size/quality/style options, Whisper audio transcription with a verbose response format and language hint, and text-to-speech generation with a selectable voice and speed.
When to use - and when NOT to
Use it for any .NET application calling Azure-hosted OpenAI models - chat completions (including streaming, RAG, and structured outputs), embeddings, image generation, or audio transcription/synthesis - through Azure OpenAI Service specifically rather than OpenAI's own API directly. Choose Microsoft Entra ID authentication over API keys for production deployments.
Inputs and outputs
Given a deployment name and a list of ChatMessage objects, chat clients return a ChatCompletion with content text, token usage, tool calls, or RAG citations, or a stream of StreamingChatCompletionUpdate objects. Embedding, image, and audio clients take text/image prompts or audio files and return float vectors, image URIs, or transcribed/synthesized audio respectively.
Integrations
dotnet add package Azure.AI.OpenAI
dotnet add package OpenAI
The OpenAI package is an optional add-on for full OpenAI-SDK compatibility against an Azure endpoint. Authenticates via AzureKeyCredential or DefaultAzureCredential against AZURE_OPENAI_ENDPOINT, with AZURE_OPENAI_API_KEY and AZURE_OPENAI_DEPLOYMENT_NAME as supporting environment variables, and can integrate with Azure AI Search for retrieval-augmented chat.
Who it's for
.NET developers building applications on Azure OpenAI Service who need chat, embeddings, image, or audio model access with production-grade authentication, streaming, RAG via Azure AI Search, function calling, structured JSON output, and support for newer reasoning models like o1 and o4-mini.
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.