Skip to content

Keyed OpenAIClient won't apply keyed/named options #9543

@Kumima

Description

@Kumima

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Description

// AppHost
IResourceBuilder<ParameterResource> deepSeekApiKey = builder.AddParameter("deepseek-api-key", true);
IResourceBuilder<ConnectionStringResource> deepSeekConnectionString = builder.AddConnectionString(
    "deepseek",
    connectionStringBuilder => connectionStringBuilder.Append(
        $"Endpoint=https://api.deepseek.com/;Key={deepSeekApiKey};Model=deepseek-chat"));

// Consumer
builder.AddKeyedOpenAIClientFromConfiguration("deepseek").AddKeyedChatClient("deepseek")
// or
builder.AddKeyedOpenAI("deepseek").AddKeyedChatClient("deepseek")
// more? such as Azure?

For keyed client, they won't apply the configured connection string. It will keep using the OpenAIClientOptions with default named option. I think the results depend on whether you've configured the default named option, if not, it will use the default value of the OpenAIClientOptions. And the connectionstring, key and model are incorrect for keyed clients.

Cause

We need to manage named option here, and I did not take further investigation for azure related, not sure whether they are using this.

var options = serviceProvider.GetRequiredService<IOptions<OpenAIClientOptions>>().Value;

Expected Behavior

Make sure keyed OpenAI related services can be configured normally.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version info

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    aiarea-integrationsIssues pertaining to Aspire Integrations packages

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions