Skip to content

OpenAIProviderExtensions

Namespace AgentPrism · Assembly AgentPrism.OpenAI.dll

Extensions that add the OpenAI provider to the AgentPrism chain.

public static class OpenAIProviderExtensions

objectOpenAIProviderExtensions

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

UseOpenAI(IAgentPrismBuilder, string, Action<OpenAIProviderOptions>?)

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

Adds the OpenAI provider with the given API key.

public static IAgentPrismBuilder UseOpenAI(this IAgentPrismBuilder builder, string apiKey, Action<OpenAIProviderOptions>? configure = null)

builder IAgentPrismBuilder

The AgentPrism chain.

apiKey string

The OpenAI API key.

configure Action<OpenAIProviderOptions>?

An extra options callback.

IAgentPrismBuilder

The same chain, for chaining.

The key is passed in by the caller; AgentPrism never reads IConfiguration on its own, and the key is never written to the database.

builder.AddAgentPrism()
.UseOpenAI(builder.Configuration["OpenAI:ApiKey"]!);

ArgumentNullException

builder is null.

ArgumentException

apiKey is empty.

UseOpenAI(IAgentPrismBuilder, IConfiguration)

Section titled “ UseOpenAI(IAgentPrismBuilder, IConfiguration)”

Adds the OpenAI provider with options read from the AgentPrism:Providers:OpenAI section.

public static IAgentPrismBuilder UseOpenAI(this IAgentPrismBuilder builder, IConfiguration configurationSection)

builder IAgentPrismBuilder

The AgentPrism chain.

configurationSection IConfiguration

The section the options are read from. Usually configuration.GetSection(OpenAIProviderOptions.SectionName).

IAgentPrismBuilder

The same chain, for chaining.

ArgumentNullException

Any parameter is null.

UseOpenAI(IAgentPrismBuilder, Action<OpenAIProviderOptions>)

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

Adds the OpenAI provider with options set in code.

public static IAgentPrismBuilder UseOpenAI(this IAgentPrismBuilder builder, Action<OpenAIProviderOptions> configure)

builder IAgentPrismBuilder

The AgentPrism chain.

configure Action<OpenAIProviderOptions>

The options callback.

IAgentPrismBuilder

The same chain, for chaining.

This call registers two providers: OpenAIProviderNames.ChatCompletions and OpenAIProviderNames.Responses. The agent definition picks the one it uses through ModelBinding.Provider.

Registration goes through AddModelProvider(...); no existing service is replaced. UsePostgreSql uses Replace because it takes the place of the existing stores; this call adds a new provider, so it has no such need.

When it is called more than once, the options are merged; the providers are registered only once.

ArgumentNullException

Any parameter is null.