OpenAIRequestPolicies Class

Definition

Provides an extension hook for adding PipelinePolicy instances to the RequestOptions built by Microsoft.Extensions.AI for every outbound OpenAI request made through the owning IChatClient or IEmbeddingGenerator.

public ref class OpenAIRequestPolicies sealed
[System.Diagnostics.CodeAnalysis.Experimental("MEAI001", UrlFormat="https://aka.ms/dotnet-extensions-warnings/{0}")]
public sealed class OpenAIRequestPolicies
public sealed class OpenAIRequestPolicies
[<System.Diagnostics.CodeAnalysis.Experimental("MEAI001", UrlFormat="https://aka.ms/dotnet-extensions-warnings/{0}")>]
type OpenAIRequestPolicies = class
type OpenAIRequestPolicies = class
Public NotInheritable Class OpenAIRequestPolicies
Inheritance
OpenAIRequestPolicies
Attributes

Remarks

Retrieve the instance via GetService(Type, Object) (or the equivalent on other Microsoft.Extensions.AI client interfaces) using OpenAIRequestPolicies as the service type. The instance is per-client and reachable through any ChatClientBuilder decorator chain.

Customer-registered policies are appended after Microsoft.Extensions.AI's own internal policies, so a policy that calls message.Request.Headers.Set("User-Agent", ...) replaces the existing value, while one that calls Headers.Add(...) stacks an additional value.

Registration is intended for one-time configuration at startup, but is safe to call concurrently with in-flight requests.

Constructors

Name Description
OpenAIRequestPolicies()

Initializes a new instance of the OpenAIRequestPolicies class.

Methods

Name Description
AddPolicy(PipelinePolicy, PipelinePosition)

Adds a PipelinePolicy to be applied to every RequestOptions produced for outbound OpenAI requests by the owning Microsoft.Extensions.AI client.

Applies to