OpenAiShim class

OpenAI-compatible API shim — direct port of neomage/src/services/api/openaiShim.ts

Translates Anthropic-format messages into OpenAI chat completion requests and streams back events in the Anthropic streaming format so the rest of the codebase is unaware of the underlying provider.

Supports: OpenAI, Azure OpenAI, Ollama, LM Studio, OpenRouter, Together, Groq, Fireworks, DeepSeek, Mistral, and any OpenAI-compatible API.

Inheritance

Constructors

OpenAiShim(ApiConfig config)
Creates a shim with the given config for an OpenAI-compatible provider.

Properties

config ApiConfig
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createMessage({required List<Message> messages, required String systemPrompt, List<ToolDefinition> tools = const [], int? maxTokens}) Future<Message>
Send a non-streaming chat completion and return the response as a Message.
override
createMessageStream({required List<Message> messages, required String systemPrompt, List<ToolDefinition> tools = const [], int? maxTokens}) Stream<StreamEvent>
Stream a chat completion, translating OpenAI SSE events to Anthropic format.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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