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) { // ... }}Parameters
builderIHostApplicationBuilder The application builder.namestringThe service key and connection-string name.Returns
AspireOpenAIClientBuilder A builder for registering keyed chat and embedding services.Exceptions
ArgumentNullExceptionbuilder is null.ArgumentExceptionThe name is empty or connection information is malformed.InvalidOperationExceptionThe connection string has neither an endpoint nor an API key.Remarks
Uses the same endpoint and authentication selection as
AspireConfigurableOpenAIExtensions.AddOpenAIClientFromConfiguration .Examples
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) { // ... }}Parameters
builderIHostApplicationBuilder The application builder.connectionName stringThe connection-string name.Returns
AspireOpenAIClientBuilder A builder for registering chat and embedding services.Exceptions
ArgumentNullExceptionbuilder is null.ArgumentExceptionThe name is empty or connection information is malformed.InvalidOperationExceptionThe connection string has neither an endpoint nor an API key.Remarks
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. Examples
builder.AddOpenAIClientFromConfiguration("chat").AddChatClient();