Skip to content

OpenaiClient ​

Category: LLM Providers

Source: openai_client.dart

Classes ​

OpenAiClient ​

LLM client for OpenAI Chat Completions API with streaming.

Compatibility quirks of OpenAI-shaped endpoints (Groq, Ollama, OpenRouter, vLLM, Mistral) are handled by the injected [CompatibilityProfile] — this client stays protocol-shaped and does not branch on vendor id.

Constructor ​

dart
OpenAiClient({
    required this.apiKey,
    required this.model,
    required this.systemPrompt,
    required this.baseUrl,
    this.profile = CompatibilityProfile.openai,
    this.extraHeaders = const {},
    this.reasoning = const ReasoningConfig(),
    http.Client Function()? requestClientFactory,
  })

Properties ​

PropertyTypeDescription
apiKeyString
modelString
systemPromptString
baseUrlString
profileCompatibilityProfile
extraHeadersMap<String, String>
reasoningReasoningConfig

Methods ​

Stream<LlmChunk> stream(List<Message> messages, {List<Tool>? tools}) ​
`static Stream<LlmChunk> parseStreamEvents( ​
Stream&lt;Map&lt;String, dynamic&gt;&gt; events, {
bool showThoughts = true,

})`

Parse OpenAI streaming chunks into [LlmChunk]s.

Exposed as static for testability.

Released under the MIT License.