Table of Contents

Class OpenAIService

Namespace
Mythosia.AI.Services.OpenAI
Assembly
Mythosia.AI.dll
public class OpenAIService : OpenAICompatibleService, IAIService, IFunctionRegisterable
Inheritance
OpenAIService
Implements
Inherited Members
Extension Methods

Constructors

OpenAIService(string, HttpClient)

public OpenAIService(string apiKey, HttpClient httpClient)

Parameters

apiKey string
httpClient HttpClient

OpenAIService(string, string, HttpClient)

Creates a OpenAIService with a specific model.

public OpenAIService(string apiKey, string model, HttpClient httpClient)

Parameters

apiKey string
model string
httpClient HttpClient

Properties

Gpt5ReasoningEffort

GPT-5 reasoning effort level. GPT-5 defaults to Medium.

public Gpt5Reasoning Gpt5ReasoningEffort { get; set; }

Property Value

Gpt5Reasoning

Gpt5ReasoningSummary

GPT-5 reasoning summary mode. Defaults to Auto. Set to null to disable reasoning summaries.

public ReasoningSummary? Gpt5ReasoningSummary { get; set; }

Property Value

ReasoningSummary?

Gpt5_1ReasoningEffort

GPT-5.1 reasoning effort level. GPT-5.1 defaults to None.

public Gpt5_1Reasoning Gpt5_1ReasoningEffort { get; set; }

Property Value

Gpt5_1Reasoning

Gpt5_1ReasoningSummary

GPT-5.1 reasoning summary mode. Defaults to Auto. Set to null to disable reasoning summaries.

public ReasoningSummary? Gpt5_1ReasoningSummary { get; set; }

Property Value

ReasoningSummary?

Gpt5_1Verbosity

GPT-5.1 verbosity level. GPT-5.1 defaults to Medium.

public Verbosity? Gpt5_1Verbosity { get; set; }

Property Value

Verbosity?

Gpt5_2ReasoningEffort

GPT-5.2 reasoning effort level. GPT-5.2 defaults to None. GPT-5.2 Pro defaults to Medium.

public Gpt5_2Reasoning Gpt5_2ReasoningEffort { get; set; }

Property Value

Gpt5_2Reasoning

Gpt5_2ReasoningSummary

GPT-5.2 reasoning summary mode. Defaults to Auto. Set to null to disable reasoning summaries.

public ReasoningSummary? Gpt5_2ReasoningSummary { get; set; }

Property Value

ReasoningSummary?

Gpt5_2Verbosity

GPT-5.2 verbosity level. GPT-5.2 defaults to Medium.

public Verbosity? Gpt5_2Verbosity { get; set; }

Property Value

Verbosity?

Gpt5_3ReasoningEffort

GPT-5.3 reasoning effort level. GPT-5.3 Codex defaults to Medium.

public Gpt5_3Reasoning Gpt5_3ReasoningEffort { get; set; }

Property Value

Gpt5_3Reasoning

Gpt5_3ReasoningSummary

GPT-5.3 reasoning summary mode. Defaults to Auto. Set to null to disable reasoning summaries.

public ReasoningSummary? Gpt5_3ReasoningSummary { get; set; }

Property Value

ReasoningSummary?

Gpt5_3Verbosity

GPT-5.3 verbosity level. GPT-5.3 defaults to Medium.

public Verbosity? Gpt5_3Verbosity { get; set; }

Property Value

Verbosity?

Gpt5_4ReasoningEffort

GPT-5.4 reasoning effort level. GPT-5.4 defaults to None. GPT-5.4 Pro defaults to Medium.

public Gpt5_4Reasoning Gpt5_4ReasoningEffort { get; set; }

Property Value

Gpt5_4Reasoning

Gpt5_4ReasoningSummary

GPT-5.4 reasoning summary mode. Defaults to Auto. Set to null to disable reasoning summaries.

public ReasoningSummary? Gpt5_4ReasoningSummary { get; set; }

Property Value

ReasoningSummary?

Gpt5_4Verbosity

GPT-5.4 verbosity level. GPT-5.4 defaults to Medium.

public Verbosity? Gpt5_4Verbosity { get; set; }

Property Value

Verbosity?

LastReasoningSummary

Contains the reasoning summary from the last non-streaming API call. Only populated when using reasoning models (GPT-5, o3) with reasoning.summary enabled.

public string? LastReasoningSummary { get; }

Property Value

string

Provider

The AI provider for this service

public override string Provider { get; }

Property Value

string

Methods

ApplyProviderSpecificRequestProfile(AIRequestProfile)

protected override Action ApplyProviderSpecificRequestProfile(AIRequestProfile profile)

Parameters

profile AIRequestProfile

Returns

Action

CreateFunctionMessageRequest()

Creates HTTP request with function definitions

protected override HttpRequestMessage CreateFunctionMessageRequest()

Returns

HttpRequestMessage

CreateMessageRequest()

Creates the HTTP request message for the AI service

protected override HttpRequestMessage CreateMessageRequest()

Returns

HttpRequestMessage

ExtractFunctionCall(string)

Extracts function call from API response

protected override (string content, FunctionCall functionCall) ExtractFunctionCall(string response)

Parameters

response string

Returns

(string content, FunctionCall functionCall)

ExtractResponseContent(string)

Extracts the response content from the API response

protected override string ExtractResponseContent(string responseContent)

Parameters

responseContent string

Returns

string

GenerateImageAsync(string, string)

Generates an image from a text prompt

public override Task<byte[]> GenerateImageAsync(string prompt, string size = "1024x1024")

Parameters

prompt string
size string

Returns

Task<byte[]>

GenerateImageUrlAsync(string, string)

Generates an image URL from a text prompt

public override Task<string> GenerateImageUrlAsync(string prompt, string size = "1024x1024")

Parameters

prompt string
size string

Returns

Task<string>

GetCompletionAsync(Message)

public override Task<string> GetCompletionAsync(Message message)

Parameters

message Message

Returns

Task<string>

GetCompletionWithImageAsync(string, string)

public override Task<string> GetCompletionWithImageAsync(string prompt, string imagePath)

Parameters

prompt string
imagePath string

Returns

Task<string>

GetInputTokenCountAsync()

Gets the token count for the current conversation

public override Task<uint> GetInputTokenCountAsync()

Returns

Task<uint>

GetInputTokenCountAsync(string)

Gets the token count for a specific prompt

public override Task<uint> GetInputTokenCountAsync(string prompt)

Parameters

prompt string

Returns

Task<uint>

GetModelMaxOutputTokens()

Returns the maximum output tokens allowed for the current model. Override in each service to provide model-specific limits.

protected override uint GetModelMaxOutputTokens()

Returns

uint

GetSpeechAsync(string, string, string)

Generates speech audio from text using OpenAI's TTS model

public Task<byte[]> GetSpeechAsync(string inputText, string voice = "alloy", string model = "tts-1")

Parameters

inputText string
voice string
model string

Returns

Task<byte[]>

ParseStreamChunk(string, StreamOptions)

Parses a single SSE JSON chunk into a provider-neutral stream chunk. Each provider overrides this to handle its specific JSON format.

protected override OpenAICompatibleService.OpenAIStreamChunk ParseStreamChunk(string jsonData, StreamOptions options)

Parameters

jsonData string
options StreamOptions

Returns

OpenAICompatibleService.OpenAIStreamChunk

StreamParseJson(string)

Parses streaming JSON data

protected override string StreamParseJson(string jsonData)

Parameters

jsonData string

Returns

string

TranscribeAudioAsync(byte[], string, string?)

Transcribes audio to text using OpenAI's Whisper model

public Task<string> TranscribeAudioAsync(byte[] audioData, string fileName, string? language = null)

Parameters

audioData byte[]
fileName string
language string

Returns

Task<string>

WithGpt5Parameters(Gpt5Reasoning, ReasoningSummary?)

Sets GPT-5 specific parameters. Reasoning effort: Minimal, Low, Medium (default), High. Reasoning summary: Auto (default), Concise, Detailed, or null to disable.

public OpenAIService WithGpt5Parameters(Gpt5Reasoning reasoningEffort = Gpt5Reasoning.Medium, ReasoningSummary? reasoningSummary = ReasoningSummary.Auto)

Parameters

reasoningEffort Gpt5Reasoning
reasoningSummary ReasoningSummary?

Returns

OpenAIService

WithGpt5_1Parameters(Gpt5_1Reasoning, Verbosity, ReasoningSummary?)

Sets GPT-5.1 specific parameters. Reasoning effort: None (default), Low, Medium, High. Verbosity: Low, Medium (default), High. Reasoning summary: Auto (default), Concise, Detailed, or null to disable.

public OpenAIService WithGpt5_1Parameters(Gpt5_1Reasoning reasoningEffort = Gpt5_1Reasoning.None, Verbosity verbosity = Verbosity.Medium, ReasoningSummary? reasoningSummary = ReasoningSummary.Auto)

Parameters

reasoningEffort Gpt5_1Reasoning
verbosity Verbosity
reasoningSummary ReasoningSummary?

Returns

OpenAIService

WithGpt5_2Parameters(Gpt5_2Reasoning, Verbosity, ReasoningSummary?)

Sets GPT-5.2 specific parameters. Reasoning effort: None (default), Low, Medium, High, XHigh. GPT-5.2 Pro supports Medium, High, XHigh. GPT-5.2 Codex supports Low, Medium (default), High, XHigh. Verbosity: Low, Medium (default), High. Reasoning summary: Auto (default), Concise, Detailed, or null to disable.

public OpenAIService WithGpt5_2Parameters(Gpt5_2Reasoning reasoningEffort = Gpt5_2Reasoning.None, Verbosity verbosity = Verbosity.Medium, ReasoningSummary? reasoningSummary = ReasoningSummary.Auto)

Parameters

reasoningEffort Gpt5_2Reasoning
verbosity Verbosity
reasoningSummary ReasoningSummary?

Returns

OpenAIService

WithGpt5_3Parameters(Gpt5_3Reasoning, Verbosity, ReasoningSummary?)

Sets GPT-5.3 specific parameters. Reasoning effort: None (default for Instant), Low, Medium (default for Codex), High, XHigh. GPT-5.3 Codex supports Low, Medium (default), High, XHigh. Verbosity: Low, Medium (default), High. Reasoning summary: Auto (default), Concise, Detailed, or null to disable.

public OpenAIService WithGpt5_3Parameters(Gpt5_3Reasoning reasoningEffort = Gpt5_3Reasoning.None, Verbosity verbosity = Verbosity.Medium, ReasoningSummary? reasoningSummary = ReasoningSummary.Auto)

Parameters

reasoningEffort Gpt5_3Reasoning
verbosity Verbosity
reasoningSummary ReasoningSummary?

Returns

OpenAIService

WithGpt5_4Parameters(Gpt5_4Reasoning, Verbosity, ReasoningSummary?)

Sets GPT-5.4 specific parameters. Reasoning effort: None (default), Low, Medium, High, XHigh. GPT-5.4 Pro supports Medium, High, XHigh. Verbosity: Low, Medium (default), High. Reasoning summary: Auto (default), Concise, Detailed, or null to disable.

public OpenAIService WithGpt5_4Parameters(Gpt5_4Reasoning reasoningEffort = Gpt5_4Reasoning.None, Verbosity verbosity = Verbosity.Medium, ReasoningSummary? reasoningSummary = ReasoningSummary.Auto)

Parameters

reasoningEffort Gpt5_4Reasoning
verbosity Verbosity
reasoningSummary ReasoningSummary?

Returns

OpenAIService

WithOpenAIParameters(float?, float?, int?)

Fine-tunes the response with specific OpenAI parameters

public OpenAIService WithOpenAIParameters(float? presencePenalty = null, float? frequencyPenalty = null, int? bestOf = null)

Parameters

presencePenalty float?
frequencyPenalty float?
bestOf int?

Returns

OpenAIService