# AspireAzureProjectOpenAIExtensions Methods

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

Registers Azure AI Project OpenAI clients with configuration and Microsoft.Extensions.AI telemetry.

<a id="addazureprojectopenaiclient"></a>
<a id="addazureprojectopenaiclient-ihostapplicationbuilder-string-action-azureprojectopenaisettings-action-iazureclientbuilder-projectopenaiclient-projectopenaiclientoptions"></a>

## AddAzureProjectOpenAIClient(IHostApplicationBuilder, string, Action<AzureProjectOpenAISettings>, Action<IAzureClientBuilder<ProjectOpenAIClient, ProjectOpenAIClientOptions>>)

- Name: `AddAzureProjectOpenAIClient(IHostApplicationBuilder, string, Action<AzureProjectOpenAISettings>, Action<IAzureClientBuilder<ProjectOpenAIClient, ProjectOpenAIClientOptions>>)`
- Modifiers: `extension`
- Returns: [AspireAzureProjectOpenAIClientBuilder](/reference/api/csharp/aspire.azure.ai.extensions.openai/aspireazureprojectopenaiclientbuilder.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Components/Aspire.Azure.AI.Extensions.OpenAI/AspireAzureProjectOpenAIExtensions.cs#L48-L54)

Registers `OpenAI.ProjectOpenAIClient` and its `OpenAIClient` alias as singletons.

```csharp
public static class AspireAzureProjectOpenAIExtensions
{
    public static AspireAzureProjectOpenAIClientBuilder AddAzureProjectOpenAIClient(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<AzureProjectOpenAISettings>? configureSettings = null,
        Action<IAzureClientBuilder<ProjectOpenAIClient, ProjectOpenAIClientOptions>>? configureClientBuilder = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The application builder.
- `connectionName` (`string`)
  The project connection-string name.
- `configureSettings` (`Action<AzureProjectOpenAISettings>`) `optional`
  Customizes settings after configuration and connection-string binding.
- `configureClientBuilder` (`Action<IAzureClientBuilder<ProjectOpenAIClient, ProjectOpenAIClientOptions>>`) `optional`
  Customizes the Azure client registration and options.

## Returns

[AspireAzureProjectOpenAIClientBuilder](/reference/api/csharp/aspire.azure.ai.extensions.openai/aspireazureprojectopenaiclientbuilder.md) -- A builder for registering model clients and Microsoft.Extensions.AI services.

## Exceptions

- `ArgumentNullException` -- `builder` is null.
- `ArgumentException` -- `connectionName` is null or empty, or the connection string is invalid.

## Remarks

Reads configuration from `Aspire:Azure:AI:Extensions:OpenAI` and its connection-specific subsection.

## Examples

```csharp
builder.AddAzureProjectOpenAIClient("project").AddChatClient("chat");
```

<a id="addkeyedazureprojectopenaiclient"></a>
<a id="addkeyedazureprojectopenaiclient-ihostapplicationbuilder-string-action-azureprojectopenaisettings-action-iazureclientbuilder-projectopenaiclient-projectopenaiclientoptions"></a>

## AddKeyedAzureProjectOpenAIClient(IHostApplicationBuilder, string, Action<AzureProjectOpenAISettings>, Action<IAzureClientBuilder<ProjectOpenAIClient, ProjectOpenAIClientOptions>>)

- Name: `AddKeyedAzureProjectOpenAIClient(IHostApplicationBuilder, string, Action<AzureProjectOpenAISettings>, Action<IAzureClientBuilder<ProjectOpenAIClient, ProjectOpenAIClientOptions>>)`
- Modifiers: `extension`
- Returns: [AspireAzureProjectOpenAIClientBuilder](/reference/api/csharp/aspire.azure.ai.extensions.openai/aspireazureprojectopenaiclientbuilder.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Components/Aspire.Azure.AI.Extensions.OpenAI/AspireAzureProjectOpenAIExtensions.cs#L79-L85)

Registers `OpenAI.ProjectOpenAIClient` and its `OpenAIClient` alias as keyed singletons.

```csharp
public static class AspireAzureProjectOpenAIExtensions
{
    public static AspireAzureProjectOpenAIClientBuilder AddKeyedAzureProjectOpenAIClient(
        this IHostApplicationBuilder builder,
        string name,
        Action<AzureProjectOpenAISettings>? configureSettings = null,
        Action<IAzureClientBuilder<ProjectOpenAIClient, ProjectOpenAIClientOptions>>? configureClientBuilder = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The application builder.
- `name` (`string`)
  The service key and project connection-string name.
- `configureSettings` (`Action<AzureProjectOpenAISettings>`) `optional`
  Customizes settings after configuration and connection-string binding.
- `configureClientBuilder` (`Action<IAzureClientBuilder<ProjectOpenAIClient, ProjectOpenAIClientOptions>>`) `optional`
  Customizes the Azure client registration and options.

## Returns

[AspireAzureProjectOpenAIClientBuilder](/reference/api/csharp/aspire.azure.ai.extensions.openai/aspireazureprojectopenaiclientbuilder.md) -- A builder for registering model clients and Microsoft.Extensions.AI services.

## Exceptions

- `ArgumentNullException` -- `builder` is null.
- `ArgumentException` -- `name` is null or empty, or the connection string is invalid.

## Remarks

Uses `name` for both configuration lookup and keyed service resolution.

## Examples

```csharp
builder.AddKeyedAzureProjectOpenAIClient("project").AddKeyedChatClient("chat-client", "chat");
```
