# AspireOpenAIClientBuilderChatClientExtensions Methods

- Package: [Aspire.OpenAI](/reference/api/csharp/aspire.openai.md)
- Type: [AspireOpenAIClientBuilderChatClientExtensions](/reference/api/csharp/aspire.openai/aspireopenaiclientbuilderchatclientextensions.md)
- Kind: `Methods`
- Members: `2`

Provides extension methods for registering `AI.IChatClient` as a singleton in the services provided by the `Hosting.IHostApplicationBuilder`.

## AddChatClient(AspireOpenAIClientBuilder, string?)

- Name: `AddChatClient(AspireOpenAIClientBuilder, string?)`
- Modifiers: `extension`
- Returns: `ChatClientBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.OpenAI/AspireOpenAIClientBuilderChatClientExtensions.cs#L27-L30)

Registers a singleton `AI.IChatClient` in the services provided by the `builder`.

```csharp
public static class AspireOpenAIClientBuilderChatClientExtensions
{
    public static ChatClientBuilder AddChatClient(
        this AspireOpenAIClientBuilder builder,
        string? deploymentName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([AspireOpenAIClientBuilder](/reference/api/csharp/aspire.openai/aspireopenaiclientbuilder.md))
  An [AspireOpenAIClientBuilder](/reference/api/csharp/aspire.openai/aspireopenaiclientbuilder.md).
- `deploymentName` (`string?`) `optional`
  Optionally specifies which model deployment to use. If not specified, a value will be taken from the connection string.

## Returns

`ChatClientBuilder` -- A `AI.ChatClientBuilder` that can be used to build a pipeline around the inner `AI.IChatClient`.

## AddKeyedChatClient(AspireOpenAIClientBuilder, string, string?)

- Name: `AddKeyedChatClient(AspireOpenAIClientBuilder, string, string?)`
- Modifiers: `extension`
- Returns: `ChatClientBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.OpenAI/AspireOpenAIClientBuilderChatClientExtensions.cs#L45-L50)

Registers a keyed singleton `AI.IChatClient` in the services provided by the `builder`.

```csharp
public static class AspireOpenAIClientBuilderChatClientExtensions
{
    public static ChatClientBuilder AddKeyedChatClient(
        this AspireOpenAIClientBuilder builder,
        string serviceKey,
        string? deploymentName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([AspireOpenAIClientBuilder](/reference/api/csharp/aspire.openai/aspireopenaiclientbuilder.md))
  An [AspireOpenAIClientBuilder](/reference/api/csharp/aspire.openai/aspireopenaiclientbuilder.md).
- `serviceKey` (`string`)
  The service key with which the `AI.IChatClient` will be registered.
- `deploymentName` (`string?`) `optional`
  Optionally specifies which model deployment to use. If not specified, a value will be taken from the connection string.

## Returns

`ChatClientBuilder` -- A `AI.ChatClientBuilder` that can be used to build a pipeline around the inner `AI.IChatClient`.
