ChatCompletionRequest

@Serializable
class ChatCompletionRequest(val messages: List<ChatMessage>, val model: ChatModel, val frequencyPenalty: Double? = null, val maxTokens: Int? = null, val presencePenalty: Double? = null, val responseFormat: ResponseFormat? = null, val stop: StopReason? = null, val stream: Boolean? = null, val streamOptions: StreamOptions? = null, val temperature: Double? = null, val topP: Double? = null, val tools: List<Tool>? = null, val toolChoice: ToolChoice? = null, val logprobs: Boolean? = null, val topLogprobs: Int? = null, val thinking: Thinking? = null, val reasoningEffort: ReasoningEffort? = null, val userId: String? = null)

Represents the Chat Completion request

Constructors

Link copied to clipboard
constructor(messages: List<ChatMessage>, model: ChatModel, frequencyPenalty: Double? = null, maxTokens: Int? = null, presencePenalty: Double? = null, responseFormat: ResponseFormat? = null, stop: StopReason? = null, stream: Boolean? = null, streamOptions: StreamOptions? = null, temperature: Double? = null, topP: Double? = null, tools: List<Tool>? = null, toolChoice: ToolChoice? = null, logprobs: Boolean? = null, topLogprobs: Int? = null, thinking: Thinking? = null, reasoningEffort: ReasoningEffort? = null, userId: String? = null)

Types

Link copied to clipboard
class Builder

Builder for non-streaming chat completion requests.

Link copied to clipboard

DSL for building a conversation history.

Link copied to clipboard

Builder for streaming chat completion requests.

Link copied to clipboard

DSL for building the multimodal content of a single UserMessage.

Properties

Link copied to clipboard

Sent as frequency_penalty, ignored by the API.

Link copied to clipboard

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.

Link copied to clipboard

The maximum number of tokens that can be generated in the chat completion.

Link copied to clipboard

A list of messages comprising the conversation so far.

Link copied to clipboard

ID of the model to use.

Link copied to clipboard

Sent as presence_penalty, ignored by the API.

Link copied to clipboard

How much reasoning the model spends before answering, while thinking mode is on. See ReasoningEffort.

Link copied to clipboard

An object specifying the format that the model must output. Setting to { "type": "json_object" } enables JSON Output, which guarantees the message the model generates is valid JSON.

Link copied to clipboard

Up to 16 sequences where the API will stop generating further tokens.

Link copied to clipboard

If set, partial message deltas will be sent. Tokens will be sent as data-only server-sent events (SSE) as they become available, with the stream terminated by a data: [DONE]

Link copied to clipboard

Options for streaming response. Only set this when you set stream: true.

Link copied to clipboard

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.

Link copied to clipboard

Switches the model between thinking and non-thinking mode. See Thinking.

Link copied to clipboard

Controls which (if any) tool is called by the model.

Link copied to clipboard
val tools: List<Tool>?

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.

Link copied to clipboard

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.

Link copied to clipboard
val 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.

Link copied to clipboard

A custom identifier of the end user behind the request, used for content safety review, KVCache isolation, scheduling isolation and privacy management. Must not carry personal data.

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String