OpenAiStreamClient class final
Streams chat completions from any OpenAI-compatible endpoint.
One implementation covers OpenAI, Azure OpenAI, Ollama (/v1),
Groq, DeepSeek, Together, LM Studio, vLLM and every other server that
speaks the /chat/completions protocol.
final client = OpenAiStreamClient(
baseUrl: 'https://api.openai.com/v1',
apiKey: 'sk-...',
);
await for (final event in client.streamChat(messages, model: 'gpt-4o')) {
if (event is AiTextDelta) stdout.write(event.text);
}
- Implemented types
Constructors
Properties
- apiKey → String?
-
Bearer token, when the endpoint requires one (Ollama doesn't).
final
- baseUrl → String
-
Base URL of the OpenAI-compatible API, e.g.
https://api.openai.com/v1orhttp://localhost:11434/v1(Ollama).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
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
streamChat(
List< AiChatMessage> messages, {required String model, double? temperature, int? maxTokens, Map<String, Object?> extraBody = const {}}) → Stream<Object> -
Streams a chat completion as a sequence of typed events.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited