CreateChatCompletionRequest class abstract

Request object for the Create chat completion endpoint.

Available extensions
Annotations
  • @freezed

Constructors

CreateChatCompletionRequest({required ChatCompletionModel model, required List<ChatCompletionMessage> messages, @JsonKey.new(includeIfNull: false) bool? store, @JsonKey.new(name: 'reasoning_effort', includeIfNull: false, unknownEnumValue: JsonKey.nullForUndefinedEnumValue) ReasoningEffort? reasoningEffort, @JsonKey.new(includeIfNull: false) Map<String, String>? metadata, @JsonKey.new(name: 'frequency_penalty', includeIfNull: false) double? frequencyPenalty, @JsonKey.new(name: 'logit_bias', includeIfNull: false) Map<String, int>? logitBias, @JsonKey.new(includeIfNull: false) bool? logprobs, @JsonKey.new(name: 'top_logprobs', includeIfNull: false) int? topLogprobs, @JsonKey.new(name: 'max_tokens', includeIfNull: false) int? maxTokens, @JsonKey.new(name: 'max_completion_tokens', includeIfNull: false) int? maxCompletionTokens, @JsonKey.new(includeIfNull: false) int? n, @JsonKey.new(includeIfNull: false) List<ChatCompletionModality>? modalities, @JsonKey.new(includeIfNull: false) PredictionContent? prediction, @JsonKey.new(includeIfNull: false) ChatCompletionAudioOptions? audio, @JsonKey.new(name: 'presence_penalty', includeIfNull: false) double? presencePenalty, @JsonKey.new(name: 'web_search_options', includeIfNull: false) WebSearchOptions? webSearchOptions, @JsonKey.new(name: 'response_format', includeIfNull: false) ResponseFormat? responseFormat, @JsonKey.new(includeIfNull: false) int? seed, @JsonKey.new(name: 'service_tier', includeIfNull: false, unknownEnumValue: JsonKey.nullForUndefinedEnumValue) CreateChatCompletionRequestServiceTier? serviceTier, @JsonKey.new(includeIfNull: false) ChatCompletionStop? stop, @JsonKey.new(includeIfNull: false) @Default.new(false) bool? stream, @JsonKey.new(name: 'stream_options', includeIfNull: false) ChatCompletionStreamOptions? streamOptions, @JsonKey.new(includeIfNull: false) double? temperature, @JsonKey.new(name: 'top_p', includeIfNull: false) double? topP, @JsonKey.new(name: 'top_k', includeIfNull: false) int? topK, @JsonKey.new(name: 'min_p', includeIfNull: false) double? minP, @JsonKey.new(name: 'top_a', includeIfNull: false) double? topA, @JsonKey.new(name: 'repetition_penalty', includeIfNull: false) double? repetitionPenalty, @JsonKey.new(includeIfNull: false) List<ChatCompletionTool>? tools, @JsonKey.new(name: 'tool_choice', includeIfNull: false) ChatCompletionToolChoiceOption? toolChoice, @JsonKey.new(name: 'parallel_tool_calls', includeIfNull: false) bool? parallelToolCalls, @JsonKey.new(includeIfNull: false) String? user, @JsonKey.new(name: 'function_call', includeIfNull: false) ChatCompletionFunctionCall? functionCall, @JsonKey.new(includeIfNull: false) List<FunctionObject>? functions, @JsonKey.new(includeIfNull: false, unknownEnumValue: JsonKey.nullForUndefinedEnumValue) Verbosity? verbosity, @JsonKey.new(includeIfNull: false) CreateChatCompletionRequestReasoning? reasoning, @JsonKey.new(includeIfNull: false) OpenRouterProviderPreferences? provider, @JsonKey.new(includeIfNull: false) List<String>? models, @JsonKey.new(includeIfNull: false, unknownEnumValue: JsonKey.nullForUndefinedEnumValue) CreateChatCompletionRequestRoute? route, @JsonKey.new(includeIfNull: false) List<String>? transforms, @JsonKey.new(includeIfNull: false) OpenRouterUsageConfig? usage})
Factory constructor for CreateChatCompletionRequest
const
factory
CreateChatCompletionRequest.fromJson(Map<String, dynamic> json)
Object construction from a JSON representation
factory

Properties

audio ChatCompletionAudioOptions?
Parameters for audio output. Required when audio output is requested with modalities: ["audio"]. Learn more.
no setterinherited
copyWith → $CreateChatCompletionRequestCopyWith<CreateChatCompletionRequest>
Create a copy of CreateChatCompletionRequest with the given fields replaced by the non-null parameter values.
no setterinherited
frequencyPenalty double?
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
no setterinherited
functionCall ChatCompletionFunctionCall?
Deprecated in favor of tool_choice.
no setterinherited
functions List<FunctionObject>?
Deprecated in favor of tools.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
logitBias Map<String, int>?
Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
no setterinherited
logprobs bool?
Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message.
no setterinherited
maxCompletionTokens int?
An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
no setterinherited
maxTokens int?
The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API.
no setterinherited
messages List<ChatCompletionMessage>
A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text, images, and audio.
no setterinherited
metadata Map<String, String>?
Developer-defined tags and values used for filtering completions in the dashboard.
no setterinherited
minP double?
Minimum probability threshold for token selection, relative to the probability of the most likely token. Only tokens with probability >= min_p * max_prob are considered.
no setterinherited
modalities List<ChatCompletionModality>?
A list of modalities that the model may use to generate the completion.
no setterinherited
model ChatCompletionModel
ID of the model to use. See the model endpoint compatibility table for details on which models work with the Chat API.
no setterinherited
models List<String>?
Multiple model options for automatic fallback. If the primary model's providers are down, rate-limited, or refuse due to content moderation, automatically tries other models.
no setterinherited
n int?
How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
no setterinherited
parallelToolCalls bool?
Whether to enable parallel function calling during tool use.
no setterinherited
prediction PredictionContent?
Configuration for a Predicted Output, which can greatly improve response times when large parts of the model response are known ahead of time. This is most common when you are regenerating a file with only minor changes to most of the content.
no setterinherited
presencePenalty double?
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
no setterinherited
provider OpenRouterProviderPreferences?
Provider routing preferences for controlling how requests are routed to different model providers.
no setterinherited
reasoning CreateChatCompletionRequestReasoning?
Reasoning configuration for controlling how the model generates and exposes its chain-of-thought reasoning.
no setterinherited
reasoningEffort ReasoningEffort?
Constrains effort on reasoning for reasoning models. Currently supported values are minimal, low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
no setterinherited
repetitionPenalty double?
Reduces repetition of tokens from the input. A value of 1.0 means no penalty. Higher values (up to 2.0) more strongly discourage repetition.
no setterinherited
responseFormat ResponseFormat?
An object specifying the format that the model must output.
no setterinherited
route CreateChatCompletionRequestRoute?
Routing strategy to use with the models array. Set to "fallback" to enable model fallback functionality.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
seed int?
This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.
no setterinherited
serviceTier CreateChatCompletionRequestServiceTier?
Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the Flex Processing service:
no setterinherited
stop ChatCompletionStop?
Up to 4 sequences where the API will stop generating further tokens.
no setterinherited
store bool?
Whether or not to store the output of this chat completion request for use in our model distillation or evals products.
no setterinherited
stream bool?
If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Example Python code.
no setterinherited
streamOptions ChatCompletionStreamOptions?
Options for streaming response. Only set this when you set stream: true.
no setterinherited
temperature double?
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
no setterinherited
toolChoice ChatCompletionToolChoiceOption?
Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools. Specifying a particular tool via {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool.
no setterinherited
tools List<ChatCompletionTool>?
A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.
no setterinherited
topA double?
Consider only tokens with "sufficiently high" probabilities based on the probability of the most likely token. Functions as a dynamic top-p filter.
no setterinherited
topK int?
Sample from the k most likely next tokens at each step. Lower k focuses on higher probability tokens, while higher k allows more diversity.
no setterinherited
topLogprobs int?
An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used.
no setterinherited
topP double?
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
no setterinherited
transforms List<String>?
List of prompt transforms applied to messages before sending to the model. Transformations are applied in order.
no setterinherited
usage OpenRouterUsageConfig?
Usage accounting configuration for detailed token usage information.
no setterinherited
user String?
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
no setterinherited
verbosity Verbosity?
Constrains the verbosity of the model's response. Lower values will result in more concise responses, while higher values will result in more verbose responses. Currently supported values are low, medium, and high.
no setterinherited
webSearchOptions WebSearchOptions?
This tool searches the web for relevant results to use in a response.
no setterinherited

Methods

map<TResult extends Object?>(TResult $default(_CreateChatCompletionRequest value)) → TResult

Available on CreateChatCompletionRequest, provided by the CreateChatCompletionRequestPatterns extension

A switch-like method, using callbacks.
mapOrNull<TResult extends Object?>(TResult? $default(_CreateChatCompletionRequest value)?) → TResult?

Available on CreateChatCompletionRequest, provided by the CreateChatCompletionRequestPatterns extension

A variant of map that fallback to returning null.
maybeMap<TResult extends Object?>(TResult $default(_CreateChatCompletionRequest value)?, {required TResult orElse()}) → TResult

Available on CreateChatCompletionRequest, provided by the CreateChatCompletionRequestPatterns extension

A variant of map that fallback to returning orElse.
maybeWhen<TResult extends Object?>(TResult $default(ChatCompletionModel model, List<ChatCompletionMessage> messages, bool? store, ReasoningEffort? reasoningEffort, Map<String, String>? metadata, double? frequencyPenalty, Map<String, int>? logitBias, bool? logprobs, int? topLogprobs, int? maxTokens, int? maxCompletionTokens, int? n, List<ChatCompletionModality>? modalities, PredictionContent? prediction, ChatCompletionAudioOptions? audio, double? presencePenalty, WebSearchOptions? webSearchOptions, ResponseFormat? responseFormat, int? seed, CreateChatCompletionRequestServiceTier? serviceTier, ChatCompletionStop? stop, bool? stream, ChatCompletionStreamOptions? streamOptions, double? temperature, double? topP, int? topK, double? minP, double? topA, double? repetitionPenalty, List<ChatCompletionTool>? tools, ChatCompletionToolChoiceOption? toolChoice, bool? parallelToolCalls, String? user, ChatCompletionFunctionCall? functionCall, List<FunctionObject>? functions, Verbosity? verbosity, CreateChatCompletionRequestReasoning? reasoning, OpenRouterProviderPreferences? provider, List<String>? models, CreateChatCompletionRequestRoute? route, List<String>? transforms, OpenRouterUsageConfig? usage)?, {required TResult orElse()}) → TResult

Available on CreateChatCompletionRequest, provided by the CreateChatCompletionRequestPatterns extension

A variant of when that fallback to an orElse callback.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Serializes this CreateChatCompletionRequest to a JSON map.
inherited
toMap() Map<String, dynamic>
Map representation of object (not serialized)
toString() String
A string representation of this object.
inherited
validateSchema() String?
Perform validations on the schema property values
when<TResult extends Object?>(TResult $default(ChatCompletionModel model, List<ChatCompletionMessage> messages, bool? store, ReasoningEffort? reasoningEffort, Map<String, String>? metadata, double? frequencyPenalty, Map<String, int>? logitBias, bool? logprobs, int? topLogprobs, int? maxTokens, int? maxCompletionTokens, int? n, List<ChatCompletionModality>? modalities, PredictionContent? prediction, ChatCompletionAudioOptions? audio, double? presencePenalty, WebSearchOptions? webSearchOptions, ResponseFormat? responseFormat, int? seed, CreateChatCompletionRequestServiceTier? serviceTier, ChatCompletionStop? stop, bool? stream, ChatCompletionStreamOptions? streamOptions, double? temperature, double? topP, int? topK, double? minP, double? topA, double? repetitionPenalty, List<ChatCompletionTool>? tools, ChatCompletionToolChoiceOption? toolChoice, bool? parallelToolCalls, String? user, ChatCompletionFunctionCall? functionCall, List<FunctionObject>? functions, Verbosity? verbosity, CreateChatCompletionRequestReasoning? reasoning, OpenRouterProviderPreferences? provider, List<String>? models, CreateChatCompletionRequestRoute? route, List<String>? transforms, OpenRouterUsageConfig? usage)) → TResult

Available on CreateChatCompletionRequest, provided by the CreateChatCompletionRequestPatterns extension

A switch-like method, using callbacks.
whenOrNull<TResult extends Object?>(TResult? $default(ChatCompletionModel model, List<ChatCompletionMessage> messages, bool? store, ReasoningEffort? reasoningEffort, Map<String, String>? metadata, double? frequencyPenalty, Map<String, int>? logitBias, bool? logprobs, int? topLogprobs, int? maxTokens, int? maxCompletionTokens, int? n, List<ChatCompletionModality>? modalities, PredictionContent? prediction, ChatCompletionAudioOptions? audio, double? presencePenalty, WebSearchOptions? webSearchOptions, ResponseFormat? responseFormat, int? seed, CreateChatCompletionRequestServiceTier? serviceTier, ChatCompletionStop? stop, bool? stream, ChatCompletionStreamOptions? streamOptions, double? temperature, double? topP, int? topK, double? minP, double? topA, double? repetitionPenalty, List<ChatCompletionTool>? tools, ChatCompletionToolChoiceOption? toolChoice, bool? parallelToolCalls, String? user, ChatCompletionFunctionCall? functionCall, List<FunctionObject>? functions, Verbosity? verbosity, CreateChatCompletionRequestReasoning? reasoning, OpenRouterProviderPreferences? provider, List<String>? models, CreateChatCompletionRequestRoute? route, List<String>? transforms, OpenRouterUsageConfig? usage)?) → TResult?

Available on CreateChatCompletionRequest, provided by the CreateChatCompletionRequestPatterns extension

A variant of when that fallback to returning null

Operators

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

Constants

frequencyPenaltyMaxValue → const double
frequencyPenaltyMinValue → const double
Validation constants
minPMaxValue → const double
minPMinValue → const double
nMaxValue → const int
nMinValue → const int
presencePenaltyMaxValue → const double
presencePenaltyMinValue → const double
propertyNames → const List<String>
List of all property names of schema
repetitionPenaltyMaxValue → const double
repetitionPenaltyMinValue → const double
temperatureMaxValue → const double
temperatureMinValue → const double
topAMaxValue → const double
topAMinValue → const double
topKMinValue → const int
topLogprobsMaxValue → const int
topLogprobsMinValue → const int
topPMaxValue → const double
topPMinValue → const double