OpenAIClient class

Core OpenAI HTTP client shared across all capability modules

This class provides the foundational HTTP functionality that all OpenAI capability implementations can use. It handles:

  • Authentication and headers
  • Request/response processing
  • Error handling
  • SSE stream parsing
  • Provider-specific configurations

Constructors

OpenAIClient.new(OpenAIConfig config)

Properties

config OpenAIConfig
final
dio ↔ Dio
latefinal
hashCode int
The hash code for this object.
no setterinherited
logger → Logger
final
providerId String
Get provider ID based on base URL for provider-specific behavior
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

buildApiMessages(List<ChatMessage> messages) List<Map<String, dynamic>>
Build API messages array from ChatMessage list
convertMessage(ChatMessage message) Map<String, dynamic>
Convert ChatMessage to OpenAI API format
delete(String endpoint) Future<Map<String, dynamic>>
Make a DELETE request
get(String endpoint) Future<Map<String, dynamic>>
Make a GET request
getRaw(String endpoint) Future<List<int>>
Make a GET request and return raw bytes
handleDioError(DioException e) LLMError
Handle Dio errors and convert them to appropriate LLM errors
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseSSEChunk(String chunk) List<Map<String, dynamic>>
Parse a Server-Sent Events (SSE) chunk from OpenAI's streaming API
postForm(String endpoint, FormData formData) Future<Map<String, dynamic>>
Make a POST request with form data
postJson(String endpoint, Map<String, dynamic> body) Future<Map<String, dynamic>>
Make a POST request with JSON body
postRaw(String endpoint, Map<String, dynamic> body) Future<List<int>>
Make a POST request and return raw bytes
postStreamRaw(String endpoint, Map<String, dynamic> body) Stream<String>
Make a POST request and return SSE stream
resetSSEBuffer() → void
Reset SSE buffer (call when starting a new stream)
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited