OpenAiBroker class
OpenAI provider — implements ChatBroker (/v1/chat/completions)
and EmbedBroker (/v1/embeddings). Filters listModels to
gpt-* / o<digit>* so the picker doesn't show whisper /
embeddings / dall-e.
- Inheritance
-
- Object
- ChatBroker
- OpenAiBroker
- Implemented types
Constructors
- OpenAiBroker({Client? client})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
Stable identifier —
'openai','anthropic','gemini','google_translate', … Used as the key inAiBrokerRegistryand as theKeyResolverlookup id.no setteroverride - label → String
-
Human label for picker UIs.
'OpenAI','Anthropic (Claude)','Google (Gemini)','Google (Translate)'.no setteroverride - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
chat(
{required String apiKey, required String model, required ChatRequest request}) → Future< String> -
Multi-turn. Returns the assistant's raw text for the final turn.
Same call as chatWithMeta, keeping only
AiCompletion.text.inherited -
chatWithMeta(
{required String apiKey, required String model, required ChatRequest request}) → Future< AiCompletion> -
Multi-turn, returning the final turn's reply with why the model
stopped and the token counts the provider reported. Every provider
call goes through here; chat, complete and completeWithMeta
are built on it.
override
-
complete(
{required String apiKey, required String model, required String system, required String user, double temperature = 0.3, int maxTokens = 2048}) → Future< String> -
Single-shot. Returns the assistant's raw text. Same call as
completeWithMeta, keeping only
AiCompletion.text.inherited -
completeWithMeta(
{required String apiKey, required String model, required String system, required String user, double temperature = 0.3, int maxTokens = 2048}) → Future< AiCompletion> -
Single-shot, returning the reply with why the model stopped and the
token counts the provider reported. Use it to tell a reply cut off at
maxTokens(AiFinishReason.maxTokens) from a complete one.inherited -
embed(
{required String apiKey, required String model, required List< String> inputs}) → Future<List< List< >double> > -
Embeds one or more texts into vectors of the model's native
dimension. Returns one vector per input, same order as
inputs; all vectors share the same length. -
listModels(
String apiKey) → Future< List< String> > -
Models suitable for the broker's primary capability, newest
first. Returns an empty list for an unset / invalid key, or for
providers that have no user-selectable model (e.g. Google
Translate v2).
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
stream(
{required String apiKey, required String model, required ChatRequest request}) → Stream< String> -
Token-streaming chat. Each event is an incremental delta —
concatenating every event yields the same string chat would
return. Closes the stream cleanly on end-of-message; errors are
surfaced via the stream.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- defaultEmbedModel → const String
- Recommended default for embed. 1536-d, cheap, well-supported.