# AspireConfigurableOpenAIExtensions Methods

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

Provides extension methods for registering `OpenAIClient` or `OpenAI.AzureOpenAIClient` as a singleton in the services provided by the `Hosting.IHostApplicationBuilder`.

## AddKeyedOpenAIClientFromConfiguration(IHostApplicationBuilder, string)

- Name: `AddKeyedOpenAIClientFromConfiguration(IHostApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `AspireOpenAIClientBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Components/Aspire.Azure.AI.OpenAI/AspireConfigurableOpenAIExtensions.cs#L59-L71)

Registers `OpenAIClient` as a singleton in the services provided by the `builder`. The concrete implementation is selected automatically from configuration.

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

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `name` (`string`)
  The name of the component, which is used as the `ServiceDescriptor.ServiceKey` of the service and also to retrieve the connection string from the ConnectionStrings configuration section.

## Returns

`AspireOpenAIClientBuilder` -- An `OpenAI.AspireOpenAIClientBuilder` that can be used to register additional services.

## AddOpenAIClientFromConfiguration(IHostApplicationBuilder, string)

- Name: `AddOpenAIClientFromConfiguration(IHostApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `AspireOpenAIClientBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Components/Aspire.Azure.AI.OpenAI/AspireConfigurableOpenAIExtensions.cs#L33-L45)

Registers `OpenAIClient` or `OpenAI.AzureOpenAIClient` as a singleton in the services provided by the `builder`. The concrete implementation is selected automatically from configuration.

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

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.

## Returns

`AspireOpenAIClientBuilder` -- An `OpenAI.AspireOpenAIClientBuilder` that can be used to register additional services.
