AspireConfigurableOpenAIExtensions Methods

ClassMethods2 members
Registers OpenAI clients with endpoint and authentication selection based on connection configuration.
AddKeyedOpenAIClientFromConfiguration(IHostApplicationBuilder, string)Section titled AddKeyedOpenAIClientFromConfiguration(IHostApplicationBuilder, string)extensionAspireOpenAIClientBuilder
Registers a keyed OpenAIClient singleton, selecting OpenAI-compatible, Azure account, or Foundry project registration from the connection string.
public static class AspireConfigurableOpenAIExtensions
{
public static AspireOpenAIClientBuilder AddKeyedOpenAIClientFromConfiguration(
this IHostApplicationBuilder builder,
string name)
{
// ...
}
}
builderIHostApplicationBuilderThe application builder.
namestringThe service key and connection-string name.
AspireOpenAIClientBuilderA builder for registering keyed chat and embedding services.
ArgumentNullExceptionbuilder is null.
ArgumentExceptionThe name is empty or connection information is malformed.
InvalidOperationExceptionThe connection string has neither an endpoint nor an API key.
Uses the same endpoint and authentication selection as AspireConfigurableOpenAIExtensions.AddOpenAIClientFromConfiguration.
builder.AddKeyedOpenAIClientFromConfiguration("chat").AddKeyedChatClient("chat-client");
AddOpenAIClientFromConfiguration(IHostApplicationBuilder, string)Section titled AddOpenAIClientFromConfiguration(IHostApplicationBuilder, string)extensionAspireOpenAIClientBuilder
Registers an OpenAIClient singleton, selecting OpenAI-compatible, Azure account, or Foundry project registration from the connection string.
public static class AspireConfigurableOpenAIExtensions
{
public static AspireOpenAIClientBuilder AddOpenAIClientFromConfiguration(
this IHostApplicationBuilder builder,
string connectionName)
{
// ...
}
}
builderIHostApplicationBuilderThe application builder.
connectionNamestringThe connection-string name.
AspireOpenAIClientBuilderA builder for registering chat and embedding services.
ArgumentNullExceptionbuilder is null.
ArgumentExceptionThe name is empty or connection information is malformed.
InvalidOperationExceptionThe connection string has neither an endpoint nor an API key.
Azure endpoints use Microsoft Entra authentication unless an account API key is supplied. Other endpoints, including Foundry Local, use the configured API key. The IsAzure connection-string field overrides Azure account detection for custom domains.
builder.AddOpenAIClientFromConfiguration("chat").AddChatClient();