# AspireConfigurableOpenAIExtensions Methods

- Package: [Aspire.Azure.AI.Extensions.OpenAI](/reference/api/csharp/aspire.azure.ai.extensions.openai.md)
- Type: [AspireConfigurableOpenAIExtensions](/reference/api/csharp/aspire.azure.ai.extensions.openai/aspireconfigurableopenaiextensions.md)
- Kind: `Methods`
- Members: `2`

Registers OpenAI clients with endpoint and authentication selection based on connection configuration.

<a id="addkeyedopenaiclientfromconfiguration"></a>
<a id="addkeyedopenaiclientfromconfiguration-ihostapplicationbuilder-string"></a>

## AddKeyedOpenAIClientFromConfiguration(IHostApplicationBuilder, string)

- Name: `AddKeyedOpenAIClientFromConfiguration(IHostApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `AspireOpenAIClientBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Components/Aspire.Azure.AI.Extensions.OpenAI/AspireConfigurableOpenAIExtensions.cs#L69-L77)

Registers a keyed `OpenAIClient` singleton, selecting OpenAI-compatible, Azure account, or Foundry project registration from the connection string.

```csharp
public static class AspireConfigurableOpenAIExtensions
{
    public static AspireOpenAIClientBuilder AddKeyedOpenAIClientFromConfiguration(
        this IHostApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The application builder.
- `name` (`string`)
  The service key and connection-string name.

## Returns

`AspireOpenAIClientBuilder` -- A builder for registering keyed chat and embedding services.

## Exceptions

- `ArgumentNullException` -- `builder` is null.
- `ArgumentException` -- The name is empty or connection information is malformed.
- `InvalidOperationException` -- The connection string has neither an endpoint nor an API key.

## Remarks

Uses the same endpoint and authentication selection as [AspireConfigurableOpenAIExtensions.AddOpenAIClientFromConfiguration(IHostApplicationBuilder, string)](/reference/api/csharp/aspire.azure.ai.extensions.openai/aspireconfigurableopenaiextensions/methods.md#addopenaiclientfromconfiguration-ihostapplicationbuilder-string).

## Examples

```csharp
builder.AddKeyedOpenAIClientFromConfiguration("chat").AddKeyedChatClient("chat-client");
```

<a id="addopenaiclientfromconfiguration"></a>
<a id="addopenaiclientfromconfiguration-ihostapplicationbuilder-string"></a>

## AddOpenAIClientFromConfiguration(IHostApplicationBuilder, string)

- Name: `AddOpenAIClientFromConfiguration(IHostApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `AspireOpenAIClientBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Components/Aspire.Azure.AI.Extensions.OpenAI/AspireConfigurableOpenAIExtensions.cs#L39-L47)

Registers an `OpenAIClient` singleton, selecting OpenAI-compatible, Azure account, or Foundry project registration from the connection string.

```csharp
public static class AspireConfigurableOpenAIExtensions
{
    public static AspireOpenAIClientBuilder AddOpenAIClientFromConfiguration(
        this IHostApplicationBuilder builder,
        string connectionName)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The application builder.
- `connectionName` (`string`)
  The connection-string name.

## Returns

`AspireOpenAIClientBuilder` -- A builder for registering chat and embedding services.

## Exceptions

- `ArgumentNullException` -- `builder` is null.
- `ArgumentException` -- The name is empty or connection information is malformed.
- `InvalidOperationException` -- The 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

```csharp
builder.AddOpenAIClientFromConfiguration("chat").AddChatClient();
```
