# OpenAICompatibleProviderExtensions

> 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.openaicompatibleproviderextensions/
> Summary: OpenAICompatibleProviderExtensions: Extensions that add named providers with an OpenAI compatible chat API to the Tracon chain (OpenRouter, Groq, vLLM, Ollama, LM Studio, ...).

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

Extensions that add named providers with an OpenAI compatible chat API to the
Tracon chain (OpenRouter, Groq, vLLM, Ollama, LM Studio, ...).

```csharp
public static class OpenAICompatibleProviderExtensions
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.openaicompatibleproviderextensions/">OpenAICompatibleProviderExtensions</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>

## Remarks

The difference from `UseOpenAI`: this call takes a **name** and
registers one or two providers (see
[OpenAIProviderOptions.EnableResponsesSurface](/api/tracon.openaiprovideroptions/#Tracon_OpenAIProviderOptions_EnableResponsesSurface)) under that name. It uses
the same `OpenAIProviderOptions` shape; the base address
([OpenAIProviderOptions.Endpoint](/api/tracon.openaiprovideroptions/#Tracon_OpenAIProviderOptions_Endpoint)) points at the compatible server.

Only the Chat Completions surface is registered; the Responses surface is
**off** by default (most compatible servers do not implement
`/v1/responses`).

## Methods

### <a id="Tracon_OpenAICompatibleProviderExtensions_UseOpenAICompatible_Tracon_ITraconBuilder_System_String_System_Action_Tracon_OpenAIProviderOptions__"></a> UseOpenAICompatible\(ITraconBuilder, string, Action<OpenAIProviderOptions\>\)

Adds a named OpenAI compatible provider whose options are set in code.

```csharp
public static ITraconBuilder UseOpenAICompatible(this ITraconBuilder builder, string name, Action<OpenAIProviderOptions> configure)
```

#### Parameters

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

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The provider name. It is limited to `[a-z0-9][a-z0-9-]{0,31}`.
[OpenAIProviderNames.ChatCompletions](/api/tracon.openaiprovidernames/#Tracon_OpenAIProviderNames_ChatCompletions) and
[OpenAIProviderNames.Responses](/api/tracon.openaiprovidernames/#Tracon_OpenAIProviderNames_Responses) are reserved.

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[OpenAIProviderOptions](/api/tracon.openaiprovideroptions/)\>

The options callback. It must set at least [OpenAIProviderOptions.Endpoint](/api/tracon.openaiprovideroptions/#Tracon_OpenAIProviderOptions_Endpoint).

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The same chain, for chaining.

#### Examples

```csharp
builder.AddTracon()
       .UseOpenAICompatible("openrouter", o =>
       {
           o.Endpoint = new Uri("https://openrouter.ai/api/v1");
           o.ApiKey   = configuration["OpenRouter:ApiKey"];
       })
       .UseOpenAICompatible("ollama", o =>
       {
           o.Endpoint = new Uri("http://localhost:11434/v1");
           // No ApiKey — the local server does not ask for one
       });
```

#### Exceptions

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

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`name` is empty, reserved, or does not match the pattern.

### <a id="Tracon_OpenAICompatibleProviderExtensions_UseOpenAICompatible_Tracon_ITraconBuilder_System_String_Microsoft_Extensions_Configuration_IConfiguration_"></a> UseOpenAICompatible\(ITraconBuilder, string, IConfiguration\)

Adds a named OpenAI compatible provider whose options are read from the
`Tracon:Providers:OpenAICompatible:{name}` section.

```csharp
public static ITraconBuilder UseOpenAICompatible(this ITraconBuilder builder, string name, IConfiguration configurationSection)
```

#### Parameters

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

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The provider name. See [OpenAICompatibleProviderExtensions.UseOpenAICompatible](/api/tracon.openaicompatibleproviderextensions/).

`configurationSection` [IConfiguration](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfiguration)

The section the options are read from. Usually
`configuration.GetSection($"{OpenAICompatibleProviderOptions.SectionName}:{name}")`.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The same chain, for chaining.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

Any parameter is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).
