ChatModel class abstract interface

A model that answers a conversation.

Implementations must:

  • translate framework errors onto the core hierarchy, so callers never see a raw SocketException or a provider's own error class;
  • honour AgenticContext.cancellation, closing the connection when it fires;
  • declare capabilities honestly in info;
  • be safe to share — a single instance serves concurrent requests.
final model = OpenAiCompatibleChatModel.openAi(apiKey: key, model: 'gpt-5.6');
final answer = await model.prompt('Explain Dart records in one sentence.');
Implementers
Available extensions

Properties

hashCode → int
The hash code for this object.
no setterinherited
info → ModelInfo
What this model is and what it supports.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkSupports(ChatRequest request) → void

Available on ChatModel, provided by the ChatModelOperations extension

Verifies this model can satisfy request.
dispose() → Future<void>
Releases every resource held by this object.
inherited
generate(ChatRequest request, {AgenticContext? context}) → Future<ChatResponse>
Generates a complete answer.
generateStructured<T>(ChatRequest request, {required String name, required JsonSchema schema, required T fromJson(JsonMap json), AgenticContext? context}) → Future<T>

Available on ChatModel, provided by the ChatModelOperations extension

Answers with a value conforming to schema.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prompt(String prompt, {String? system, double? temperature, int? maxOutputTokens, AgenticContext? context}) → Future<String>

Available on ChatModel, provided by the ChatModelOperations extension

Answers a single prompt and returns the text.
stream(ChatRequest request, {AgenticContext? context}) → Stream<ChatChunk>
Generates an answer incrementally.
toString() → String
A string representation of this object.
inherited

Operators

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