ChatRequest class final
An immutable request to a chat model.
final request = ChatRequest(
messages: [
Message.system('You are a concise assistant.'),
Message.user('What is the capital of France?'),
],
temperature: 0.2,
maxOutputTokens: 256,
);
- Annotations
-
- @immutable
Constructors
-
ChatRequest({required List<
Message> messages, ToolSet? tools, ToolChoice toolChoice = ToolChoice.auto, double? temperature, double? topP, int? topK, int? maxOutputTokens, List<String> stopSequences = const <String>[], int? seed, ResponseFormat responseFormat = ResponseFormat.text, ReasoningEffort? reasoningEffort, double? frequencyPenalty, double? presencePenalty, String? user, Map<String, Object?> providerOptions = const <String, Object?>{}, Map<String, Object?> metadata = const <String, Object?>{}}) - Creates a request.
- ChatRequest.prompt(String prompt, {String? system, double? temperature, int? maxOutputTokens, ResponseFormat responseFormat = ResponseFormat.text})
-
Creates a single-turn request from a prompt.
factory
Properties
- cacheKey → String
-
A stable fingerprint of everything that affects the answer.
no setter
- frequencyPenalty → double?
-
Penalty for token frequency, -2 to 2.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasTools → bool
-
Whether any tools are offered.
no setter
- maxOutputTokens → int?
-
Maximum completion tokens.
final
-
messages
→ List<
Message> -
The conversation, oldest first.
final
-
metadata
→ Map<
String, Object?> -
Application metadata, never sent to a provider.
final
- presencePenalty → double?
-
Penalty for token presence, -2 to 2.
final
-
providerOptions
→ Map<
String, Object?> -
Provider-specific fields merged into the request body.
final
- reasoningEffort → ReasoningEffort?
-
How much internal reasoning to spend.
final
-
requirements
→ Set<
ModelCapabilityRequirement> -
Capabilities this request requires of a model.
no setter
- responseFormat → ResponseFormat
-
The shape the answer must take.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- seed → int?
-
Seed for reproducible sampling, where supported.
final
-
stopSequences
→ List<
String> -
Sequences that stop generation when produced.
final
- temperature → double?
-
Sampling temperature, 0 to 2.
final
- toolChoice → ToolChoice
-
How the model may use tools.
final
- tools → ToolSet?
-
Tools the model may call, or
nullwhen none are offered.final - topK → int?
-
Top-k sampling. Supported by Anthropic and Gemini, ignored by OpenAI.
final
- topP → double?
-
Nucleus sampling threshold, 0 to 1.
final
- user → String?
-
Opaque end-user identifier, forwarded for provider-side abuse detection.
final
- wantsStructuredOutput → bool
-
Whether a structured answer was requested.
no setter
Methods
-
copyWith(
{List< Message> ? messages, ToolSet? tools, ToolChoice? toolChoice, double? temperature, double? topP, int? topK, int? maxOutputTokens, List<String> ? stopSequences, int? seed, ResponseFormat? responseFormat, ReasoningEffort? reasoningEffort, double? frequencyPenalty, double? presencePenalty, String? user, Map<String, Object?> ? providerOptions, Map<String, Object?> ? metadata}) → ChatRequest - Returns a copy with selected fields replaced.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
withMessages(
Iterable< Message> additional) → ChatRequest -
Returns a copy with
additionalmessages appended.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited