OpenAIChatCompletionRequest
OpenAI chat completion request body.
Represents the raw JSON payload sent to the /chat/completions endpoint. For provider-agnostic usage, prefer ChatRequest with toOpenAIChatCompletionRequest, or build instances with the io.kory.openai.completions.dsl.openAIChatCompletionRequest DSL.
Samples
// Initial conversation history.
val messages: List<OpenAIMessageParam> = openAIMessageParams {
system("You are a helpful assistant.")
user("What's the weather like in London?")
}
// Tool definition with strict schema adherence.
val getWeatherTool = OpenAiChatCompletionFunctionTool(
type = "function",
function = OpenAIFunctionDefinition(
name = "get_weather",
description = "Gets the current weather for a city",
parameters = buildJsonObject {
put("type", "object")
putJsonObject("properties") {
putJsonObject("city") { put("type", "string") }
}
putJsonArray("required") { add("city") }
},
strict = true
)
)
// Build a fully configured request with the DSL.
return openAIChatCompletionRequest(model = "gpt-5.6-sol") {
temperature = 0.7
topP = 1.0
maxCompletionTokens = 1024
seed = 42L
stop = OpenAIStop.OpenAIList(listOf("\n\n", "###"))
presencePenalty = 0.1
frequencyPenalty = 0.1
logprobs = true
topLogprobs = 5
parallelToolCalls = true
toolChoice = OpenAIToolChoice.Auto
responseFormat = OpenAIResponseFormat.JsonObject
verbosity = OpenAIVerbosity.LOW
serviceTier = OpenAIServiceTier.Auto
store = false
safetyIdentifier = "user-123"
metadata = openAIMetadata {
"project" to "kory"
"env" to "examples"
}
streamOptions = OpenAIStreamOptions(includeUsage = true)
messages(messages)
tool(getWeatherTool)
}Constructors
Secondary constructor using choicesCount as an alias for n.
Properties
Audio output parameters for audio generation. null disables audio output.
Penalty for token frequency (-2.0 to 2.0). Positive values decrease repetition.
Upper bound for tokens generated in a completion, including visible output tokens and reasoning tokens.
The maximum number of tokens that can be generated. Deprecated in favor of maxCompletionTokens and not compatible with reasoning models. null omits the field.
The list of message parameters.
Set of up to 16 key-value pairs attached to the request object. null omits the field.
Output modalities to generate (e.g. text, audio).
Whether to enable parallel function calling during tool use. null omits the field (provider default applies).
Penalty for token presence (-2.0 to 2.0). Positive values increase the likelihood of talking about new topics.
Reasoning effort level. null uses provider default.
An object specifying the format that the model must output. null uses the default text format.
A stable identifier for users of your application that may be violating usage policies. Recommend hashing usernames or emails to avoid sending identifying information. Max 64 characters. null omits the field.
Specifies the processing type used for serving the request. null omits the field (defaults to auto).
Up to 4 sequences where the API stops generating further tokens. Not supported by the latest reasoning models. null omits the field.
Options for streaming responses. Only set this when stream is true.
Sampling temperature (0.0–2.0). Higher values make output more random.
Controls which (if any) tool is called by the model. null uses the default: none when no tools are present, auto when tools are present.
Available tool definitions. Defaults to an empty list (no tools).
An integer between 0 and 20 specifying the maximum number of most likely tokens to return at each token position. Requires logprobs set to true.
Deprecated. Replaced by safetyIdentifier and prompt_cache_key. A stable identifier for end-users used to boost cache hit rates and detect abuse.
Constrains the verbosity of the model's response. null uses the default (medium).