Skip to content

OpenAICompatibleProviderExtensions

Namespace AgentPrism · Assembly AgentPrism.OpenAI.dll

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

public static class OpenAICompatibleProviderExtensions

objectOpenAICompatibleProviderExtensions

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

The difference from UseOpenAI: this call takes a name and registers one or two providers (see OpenAIProviderOptions.EnableResponsesSurface) under that name. It uses the same OpenAIProviderOptions shape; the base address (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).

UseOpenAICompatible(IAgentPrismBuilder, string, Action<OpenAIProviderOptions>)

Section titled “ UseOpenAICompatible(IAgentPrismBuilder, string, Action<OpenAIProviderOptions>)”

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

public static IAgentPrismBuilder UseOpenAICompatible(this IAgentPrismBuilder builder, string name, Action<OpenAIProviderOptions> configure)

builder IAgentPrismBuilder

The AgentPrism chain.

name string

The provider name. It is limited to [a-z0-9][a-z0-9-]{0,31}. OpenAIProviderNames.ChatCompletions and OpenAIProviderNames.Responses are reserved.

configure Action<OpenAIProviderOptions>

The options callback. It must set at least OpenAIProviderOptions.Endpoint.

IAgentPrismBuilder

The same chain, for chaining.

builder.AddAgentPrism()
.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
});

ArgumentNullException

builder or configure is null.

ArgumentException

name is empty, reserved, or does not match the pattern.

UseOpenAICompatible(IAgentPrismBuilder, string, IConfiguration)

Section titled “ UseOpenAICompatible(IAgentPrismBuilder, string, IConfiguration)”

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

public static IAgentPrismBuilder UseOpenAICompatible(this IAgentPrismBuilder builder, string name, IConfiguration configurationSection)

builder IAgentPrismBuilder

The AgentPrism chain.

name string

The provider name. See OpenAICompatibleProviderExtensions.UseOpenAICompatible.

configurationSection IConfiguration

The section the options are read from. Usually configuration.GetSection($"{OpenAICompatibleProviderOptions.SectionName}:{name}").

IAgentPrismBuilder

The same chain, for chaining.

ArgumentNullException

Any parameter is null.