# AzureOpenAIProviderExtensions

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.azureopenaiproviderextensions/
> Summary: AzureOpenAIProviderExtensions: Extensions that add the Azure OpenAI provider to the Tracon chain.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Azure.dll</code></div>

Extensions that add the Azure OpenAI provider to the Tracon chain.

```csharp
public static class AzureOpenAIProviderExtensions
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.azureopenaiproviderextensions/">AzureOpenAIProviderExtensions</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Methods

### <a id="Tracon_AzureOpenAIProviderExtensions_UseAzureOpenAI_Tracon_ITraconBuilder_System_Uri_System_String_System_Action_Tracon_AzureOpenAIProviderOptions__"></a> UseAzureOpenAI\(ITraconBuilder, Uri, string, Action<AzureOpenAIProviderOptions\>?\)

Adds the Azure OpenAI provider by giving an endpoint and API key.

```csharp
public static ITraconBuilder UseAzureOpenAI(this ITraconBuilder builder, Uri endpoint, string apiKey, Action<AzureOpenAIProviderOptions>? configure = null)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`endpoint` Uri

The Azure OpenAI resource's address.

`apiKey` [string](https://learn.microsoft.com/dotnet/api/system.string)

The resource's API key.

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[AzureOpenAIProviderOptions](/api/tracon.azureopenaiprovideroptions/)\>?

An extra option modifier.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Remarks

To use a managed credential, use
[AzureOpenAIProviderExtensions.UseAzureOpenAI](/api/tracon.azureopenaiproviderextensions/)
instead of this overload, and give [AzureOpenAIProviderOptions.CredentialFactory](/api/tracon.azureopenaiprovideroptions/#Tracon_AzureOpenAIProviderOptions_CredentialFactory).

```csharp
builder.AddTracon()
       .UseAzureOpenAI(
           new Uri(builder.Configuration["AzureOpenAI:Endpoint"]!),
           builder.Configuration["AzureOpenAI:ApiKey"]!);
```

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`builder`
or
`endpoint`
is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`apiKey` is empty.

### <a id="Tracon_AzureOpenAIProviderExtensions_UseAzureOpenAI_Tracon_ITraconBuilder_Microsoft_Extensions_Configuration_IConfiguration_"></a> UseAzureOpenAI\(ITraconBuilder, IConfiguration\)

Adds the Azure OpenAI provider by reading options from the
`Tracon:Providers:AzureOpenAI` section.

```csharp
public static ITraconBuilder UseAzureOpenAI(this ITraconBuilder builder, IConfiguration configurationSection)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`configurationSection` [IConfiguration](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfiguration)

The section to read options from. Typically
`configuration.GetSection(AzureOpenAIProviderOptions.SectionName)`.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Remarks

[AzureOpenAIProviderOptions.CredentialFactory](/api/tracon.azureopenaiprovideroptions/#Tracon_AzureOpenAIProviderOptions_CredentialFactory) cannot be read from
configuration; call the [AzureOpenAIProviderExtensions.UseAzureOpenAI](/api/tracon.azureopenaiproviderextensions/)
overload afterward to set it in code.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`builder`
or
`configurationSection`
is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

### <a id="Tracon_AzureOpenAIProviderExtensions_UseAzureOpenAI_Tracon_ITraconBuilder_System_Action_Tracon_AzureOpenAIProviderOptions__"></a> UseAzureOpenAI\(ITraconBuilder, Action<AzureOpenAIProviderOptions\>\)

Adds the Azure OpenAI provider by giving options in code.

```csharp
public static ITraconBuilder UseAzureOpenAI(this ITraconBuilder builder, Action<AzureOpenAIProviderOptions> configure)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[AzureOpenAIProviderOptions](/api/tracon.azureopenaiprovideroptions/)\>

The option modifier.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Remarks

This call registers exactly one provider: [AzureOpenAIProviderNames.AzureOpenAI](/api/tracon.azureopenaiprovidernames/#Tracon_AzureOpenAIProviderNames_AzureOpenAI).

Registration happens through `AddModelProvider(...)`; no existing
service is *replaced*. When called more than
once, the options are merged; the provider is registered only once.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

One of the parameters is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).
