AspireAzureOpenAIExtensions Methods

ClassMethods2 members
Registers standard OpenAI SDK clients for Azure OpenAI accounts with Microsoft Entra authentication and telemetry.
AddAzureOpenAIClient(IHostApplicationBuilder, string, Action<AzureOpenAISettings>, Action<IAzureClientBuilder<OpenAIClient, OpenAIClientOptions>>)Section titled AddAzureOpenAIClient(IHostApplicationBuilder, string, Action<AzureOpenAISettings>, Action<IAzureClientBuilder<OpenAIClient, OpenAIClientOptions>>)extensionAspireAzureOpenAIClientBuilder
Registers an OpenAIClient singleton for an Azure OpenAI account's v1 API.
public static class AspireAzureOpenAIExtensions
{
public static AspireAzureOpenAIClientBuilder AddAzureOpenAIClient(
this IHostApplicationBuilder builder,
string connectionName,
Action<AzureOpenAISettings>? configureSettings = null,
Action<IAzureClientBuilder<OpenAIClient, OpenAIClientOptions>>? configureClientBuilder = null)
{
// ...
}
}
builderIHostApplicationBuilderThe application builder.
connectionNamestringThe account connection-string name.
configureSettingsAction<AzureOpenAISettings>optionalCustomizes settings after configuration and connection-string binding.
configureClientBuilderAction<IAzureClientBuilder<OpenAIClient, OpenAIClientOptions>>optionalCustomizes the Azure client registration, credential, and OpenAI SDK options.
AspireAzureOpenAIClientBuilderA builder for registering chat, embedding, and Microsoft.Extensions.AI services.
ArgumentNullExceptionbuilder is null.
ArgumentExceptionconnectionName is null or empty, or the connection string is invalid.
Reads Aspire:Azure:AI:OpenAI and its connection-specific subsection. Account endpoints are normalized to /openai/v1/. Uses Microsoft Entra authentication unless an API key is supplied.
builder.AddAzureOpenAIClient("chat").AddChatClient();
AddKeyedAzureOpenAIClient(IHostApplicationBuilder, string, Action<AzureOpenAISettings>, Action<IAzureClientBuilder<OpenAIClient, OpenAIClientOptions>>)Section titled AddKeyedAzureOpenAIClient(IHostApplicationBuilder, string, Action<AzureOpenAISettings>, Action<IAzureClientBuilder<OpenAIClient, OpenAIClientOptions>>)extensionAspireAzureOpenAIClientBuilder
Registers a keyed OpenAIClient singleton for an Azure OpenAI account's v1 API.
public static class AspireAzureOpenAIExtensions
{
public static AspireAzureOpenAIClientBuilder AddKeyedAzureOpenAIClient(
this IHostApplicationBuilder builder,
string name,
Action<AzureOpenAISettings>? configureSettings = null,
Action<IAzureClientBuilder<OpenAIClient, OpenAIClientOptions>>? configureClientBuilder = null)
{
// ...
}
}
builderIHostApplicationBuilderThe application builder.
namestringThe service key and account connection-string name.
configureSettingsAction<AzureOpenAISettings>optionalCustomizes settings after configuration and connection-string binding.
configureClientBuilderAction<IAzureClientBuilder<OpenAIClient, OpenAIClientOptions>>optionalCustomizes the Azure client registration, credential, and OpenAI SDK options.
AspireAzureOpenAIClientBuilderA builder for registering chat, embedding, and Microsoft.Extensions.AI services.
ArgumentNullExceptionbuilder is null.
ArgumentExceptionname is null or empty, or the connection string is invalid.
Uses name for configuration lookup and keyed resolution. Account endpoints use the v1 API.
builder.AddKeyedAzureOpenAIClient("chat").AddKeyedChatClient("chat-client", "deployment");