CrestApps.Core Azure OpenAI
The CrestApps.Core.AI.OpenAI.Azure package connects CrestApps.Core to Azure OpenAI (client name "Azure") and to Azure AI Speech (client name "AzureSpeech"). Use it for enterprise workloads that need regional data residency, managed identity, or private networking.
Guidelines
- Keep the endpoint and credentials on the connection; keep the Azure deployment name and its capabilities on the deployment.
- Always set
AuthenticationTypeon an Azure connection. When it is empty the provider usesDefaultAzureCredential, even if anApiKeyis present. - Every configured deployment must declare
Features. An entry with no features and no legacyPurpose/Typeis skipped with the warning "declares no model capabilities". - Resolve deployments through slots with
IAIDeploymentManager.ResolveSlotAsync(AIDeploymentSlotNames.X, ...). - See
crestapps-core-openaifor the sharedChatApi, feature, and slot details, andcrestapps-core-realtime-voicefor voice sessions.
Registration
using CrestApps.Core.AI.OpenAI.Azure;
builder.Services.AddCrestAppsCore(crestApps => crestApps
.AddAISuite(ai => ai
.AddAzureOpenAI()
)
);
Without the suite builder, register the core and orchestration services too; AddCoreAIAzureOpenAI() alone adds only the provider:
builder.Services
.AddCoreAIServices()
.AddCoreAIOrchestration()
.AddCoreAIAzureOpenAI();
AddCoreAIAzureOpenAI() registers AzureOpenAIClientProvider (chat, embeddings, images, speech-to-text, realtime), AzureSpeechClientProvider (Azure AI Speech speech-to-text and text-to-speech), AzureOpenAIConnectionHandler, the AzureOpenAICompletionClient completion client for "Azure", AzureClientOptions bound from CrestApps:AI:AzureClient, and two deployment providers: "Azure" and the contained-connection "AzureSpeech".
Connection
{
"CrestApps": {
"AI": {
"Connections": [
{
"Name": "azure-production",
"ClientName": "Azure",
"Endpoint": "https://my-resource.openai.azure.com/",
"AuthenticationType": "ApiKey",
"ApiKey": "your-api-key"
},
{
"Name": "azure-managed",
"ClientName": "Azure",
"Endpoint": "https://my-resource.openai.azure.com/",
"AuthenticationType": "ManagedIdentity",
"IdentityId": "user-assigned-client-id"
}
]
}
}
}
| AuthenticationType | Credential used |
|---|---|
| Default or empty | DefaultAzureCredential (environment, workload identity, managed identity, Azure CLI, Visual Studio) |
| ApiKey | ApiKeyCredential(ApiKey) |
| ManagedIdentity | ManagedIdentityCredential, system-assigned when IdentityId is empty, otherwise the user-assigned client ID |
For managed identity, grant the hosting identity the Cognitive Services OpenAI User role on the resource. "AzureOpenAI" is accepted as an alias of the "Azure" client name.
Shared Azure SDK options
CrestApps:AI:AzureClient binds AzureClientOptions for every Azure OpenAI connection:
{
"CrestApps": {
"AI": {
"AzureClient": {
"EnableDefaultRetryPolicy": true,
"MaxRetryAttempts": 5,
"RateLimitRetryDelay": "00:00:01",
"BackoffType": "Exponential",
"UseJitter": true,
"MaxRetryDelay": "00:00:32",
"EnableLogging": false,
"EnableMessageLogging": false,
"EnableMessageContentLogging": false
}
}
}
}
Deployments
{
"CrestApps": {
"AI": {
"Deployments": [
{
"ClientName": "Azure",
"ConnectionName": "azure-production",
"Name": "gpt-4o",
"ModelName": "my-gpt-4o-deployment",
"Features": [ "textGeneration", "toolCalling", "streaming", "imageInput" ]
},
{
"ClientName": "Azure",
"ConnectionName": "azure-production",
"Name": "gpt-5-reasoning",
"ModelName": "gpt-5",
"Features": [ "textGeneration", "toolCalling", "streaming", "reasoning" ],
"Parameters": {
"reasoningEffort": { "DefaultValue": "None" }
}
},
{
"ClientName": "Azure",
"ConnectionName": "azure-production",
"Name": "text-embedding-3-large",
"Features": [ "textEmbedding" ]
},
{
"ClientName": "Azure",
"ConnectionName": "azure-production",
"Name": "gpt-4o-transcribe",
"Features": [ "speechToText" ]
},
{
"ClientName": "Azure",
"ConnectionName": "azure-production",
"Name": "gpt-realtime",
"Features": [ "realtime" ]
},
{
"ClientName": "AzureSpeech",
"Name": "azure-tts",
"Endpoint": "https://eastus.tts.speech.microsoft.com",
"AuthenticationType": "ApiKey",
"ApiKey": "your-speech-key",
"Features": [ "textToSpeech" ]
},
{
"ClientName": "AzureSpeech",
"Name": "azure-stt",
"Endpoint": "https://eastus.stt.speech.microsoft.com",
"AuthenticationType": "ApiKey",
"ApiKey": "your-speech-key",
"Features": [ "speechToText" ]
}
]
}
}
}
ModelNameis the Azure deployment name used in the request URL; it does not have to match the model. It falls back toName.AzureSpeechdeployments carry their own connection: top-levelEndpoint,AuthenticationType,ApiKeyandIdentityIdbecome deployment properties, so noConnectionNameis needed.- Declare
toolCallingandstreamingon chat deployments; undeclared features are enforced away (tools stripped, streaming completed as one response). - A connection can also declare
ChatDeploymentName,UtilityDeploymentName,EmbeddingDeploymentName,ImagesDeploymentName,SpeechToTextDeploymentNameorTextToSpeechDeploymentName; each becomes a read-only deployment with fixed capabilities (chat getstextGeneration,toolCallingandstreaming).
Fill slot defaults with DefaultAIDeploymentSettings (DefaultChatDeploymentName, DefaultUtilityDeploymentName, DefaultEmbeddingDeploymentName, DefaultImageDeploymentName, DefaultVisionDeploymentName, DefaultSpeechToTextDeploymentName, DefaultTextToSpeechDeploymentName, DefaultRealtimeDeploymentName) and resolve them:
using CrestApps.Core.AI.Clients;
using CrestApps.Core.AI.Deployments;
using CrestApps.Core.AI.Models;
using Microsoft.Extensions.AI;
namespace MyApp.Services;
#pragma warning disable MEAI001 // Microsoft.Extensions.AI speech APIs are evaluation-only.
public sealed class SpeechSynthesisService
{
private readonly IAIDeploymentManager _deploymentManager;
private readonly IAIClientFactory _clientFactory;
public SpeechSynthesisService(IAIDeploymentManager deploymentManager, IAIClientFactory clientFactory)
{
_deploymentManager = deploymentManager;
_clientFactory = clientFactory;
}
public async Task<TextToSpeechResponse> SpeakAsync(string text, string voice, CancellationToken cancellationToken = default)
{
var deployment = await _deploymentManager.ResolveSlotOrThrowAsync(AIDeploymentSlotNames.TextToSpeech);
var client = await _clientFactory.CreateTextToSpeechClientAsync(deployment);
return await client.GetAudioAsync(
text,
new TextToSpeechOptions
{
VoiceId = voice,
AudioFormat = "Pcm24000",
Speed = 1.1f,
},
cancellationToken);
}
}
#pragma warning restore MEAI001
Azure AI Speech Formats and Speed
AzureSpeechServiceTextToSpeechClient honors TextToSpeechOptions.AudioFormat and reports the matching media type. Names are case-insensitive: Pcm8000, Pcm16000, Pcm24000, Pcm48000 (raw PCM, audio/L16), Riff8000 through Riff48000 (WAV), Mp3, Mp3_16000, Mp3_24000, Mp3_48000, or a Speech SDK format name. MP3 at 16 kHz is the default. Raw PCM is what lets Azure Speech be the speaking leg of a cascaded realtime deployment. TextToSpeechOptions.Speed is applied as SSML prosody rate within 0.5 to 2 when a voice is named. Azure Speech has no realtime client, so it cannot be a cascade's speech-to-text leg.
The AzureSpeech text-to-speech client is wrapped in SpeechMarkupTextToSpeechClient, so neutral speech markup (<break time="500ms"/>, <spell>AB12</spell>) is rendered as plain punctuation and spaced letters instead of being read aloud (see crestapps-core-speech-voices). The "Azure" (Azure OpenAI) provider has no text-to-speech client; use AzureSpeech, OpenAI, ElevenLabs or Cartesia for the speaking leg.
Responses API and Realtime
- A chat request with function tools and a reasoning effort other than
Nonegoes to/openai/v1/responses(withstore: false); every other request stays on Chat Completions. Set the connection'sChatApitoChatCompletionsto turn this off, for example in a region without the Responses API. The routing uses a temporary built-in client (CrestApps.Core.AI.OpenAI.Azure.Responses) because the pinnedAzure.AI.OpenAISDK throwsMissingMethodExceptionon its own Responses client. - A reasoning effort is sent only when the deployment declares
reasoningandreasoningEffort.Noneis sent as"none";ExtraHighis clamped toHighwith a log entry. - Both the Chat Completions and Responses paths stream
FunctionCallContentandFunctionResultContent, pause for approval-required tools in AG-UI runs, resume approved calls, offer AG-UI client tool declarations, and send replayed tool calls and results back to the service (seecrestapps-core-ag-ui). - Realtime deployments connect to
/openai/v1/realtimethrough a temporary WebSocket transport (CrestApps.Core.AI.OpenAI.Azure.Realtime) that supports API keys and Microsoft Entra ID. Voices areOpenAIRealtimeVoices.All. Add a speech-to-text deployment (for examplegpt-4o-transcribe) on the same Azure provider so the user's realtime turns are transcribed.
Troubleshooting
CredentialUnavailableExceptionor 401 with an API key configured:AuthenticationTypeis missing, soDefaultAzureCredentialwas used. Set"AuthenticationType": "ApiKey".DeploymentNotFound: theModelNamedoes not exist on the resource the connection points at. Failed completions log the deployment name, model name, connection name, and endpoint host.- HTTP 400
unsupported_valuefor reasoning effort: declare the allowedreasoningEffortvalues the model accepts and pick a valid default. - Two connections whose names differ only by case (for example under
CrestApps:AI:ConnectionsandCrestApps:AI:Providers:Azure:Connections): the first wins and the second is logged as a warning.
Upgrading from 1.x
- Replace
"Type": "Chat"/"Purpose": "Chat"withFeatures. LegacyPurpose,CapabilityandTypevalues still load, but the projection is narrow:ChatorUtilitybecomestextGenerationonly (not whenrealtimeis declared), andEmbedding,Image,Vision,SpeechToTextandTextToSpeechbecometextEmbedding,imageOutput,imageInput,speechToTextandtextToSpeech. A 1.x chat entry therefore loses tool calling and streaming untiltoolCallingandstreamingare declared. - Replace
ResolveOrDefaultAsync(AIDeploymentPurpose.X, ...)withResolveSlotAsync(AIDeploymentSlotNames.X, ...)andGetByPurposeAsync/GetAllByPurposeAsyncwithGetAllBySlotAsync. AzureOpenAICompletionClientnow takes anIAIClientFactoryconstructor argument; code that constructs it directly must pass one.- A realtime model is a deployment that declares
realtime;ChatMode.RealtimeandAIProfile.RealtimeDeploymentNameare removed.