OpenAiCompatibleBackend

public sealed class OpenAiCompatibleBackend : IAiBackend
IAiBackend implementation talking the OpenAI Chat Completions wire format. The system/user/assistant message shape is flat (no nested content blocks like Anthropic, no separate systemInstruction like Gemini) and tool calls round-trip through an explicit tool_call_id. Forces tool_choice = "required" so the model cannot answer in prose -- the conversation loop expects every turn to be a tool invocation. This class is provider-neutral: OpenAI and DeepSeek both speak the same schema, differing only in endpoint URL and default model. The caller supplies those at construction.

Constructors

OpenAiCompatibleBackend

#
public OpenAiCompatibleBackend(
provider,
Which provider this backend talks to. Used for the Provider property and in error messages.
endpoint,
Full URL of the chat-completions endpoint, e.g. https://api.openai.com/v1/chat/completions.
defaultModel,
Initial value for Model. The caller can override it later.
apiKey
Bearer token passed in the Authorization header.
)

Properties

MaxRetries

#
Maximum number of automatic 429/503 retries before giving up.
public int MaxRetries { get; set; }

MaxTokens

#
Maximum tokens the model may produce in a single turn.
public int MaxTokens { get; set; }

Model

#
Model identifier passed to the API.
public string Model { get; set; }

Provider

#
public AiProvider Provider { get; }
Provider

TranscriptCallback

#
Optional hook invoked with (requestJson, responseBody) after every HTTP exchange, including non-2xx responses and retries. The host uses this to maintain a complete transcript of what was sent and received. Backends must invoke this before throwing on non-success status codes.
public Action<string, string> TranscriptCallback { get; set; }
TranscriptCallback

Methods

Generate

#
public Task<AiBackendResponse> Generate(
history,
tools,
cancellation
)
Generate