OpenAIChatCompletionResponse
@Serializable
Raw OpenAI chat completion response.
Contains the full response from the /chat/completions endpoint, including choices, usage statistics, and metadata. Use toChatResponse to convert to the provider-agnostic ChatResponse.
Example:
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1699892447,
"model": "gpt-5.6-sol",
"choices": [{ "index": 0, "message": { "role": "assistant", "content": "Hi!" }, "finish_reason": "stop" }],
"usage": { "prompt_tokens": 5, "completion_tokens": 7, "total_tokens": 12 }
}Content copied to clipboard
Samples
// Response metadata.
println("id: ${response.id}")
println("model: ${response.model}")
println("serviceTier: ${response.serviceTier}")
println("systemFingerprint: ${response.systemFingerprint}")
// Token usage with detailed breakdowns.
response.usage?.let { usage ->
println("promptTokens: ${usage.promptTokens}")
println("completionTokens: ${usage.completionTokens}")
println("totalTokens: ${usage.totalTokens}")
println("cachedTokens: ${usage.promptTokensDetails?.cachedTokens}")
println("reasoningTokens: ${usage.completionTokensDetails?.reasoningTokens}")
}
for (choice in response.choices) {
println("choice #${choice.index} (finishReason=${choice.finishReason})")
// Refusal, if the model declined the request.
choice.message.refusal?.let { println("refusal: $it") }
// Audio output, when the audio modality was requested.
choice.message.audio?.let { audio ->
println("audioId: ${audio.id}")
println("transcript: ${audio.transcript}")
}
// Log probabilities, when logprobs=true was set on the request.
choice.logprobs?.content?.forEach { token ->
println("token='${token.token}' logprob=${token.logprob}")
}
// Convert to provider-agnostic content.
val chatChoice = choice.toChatChoice()
for (content in chatChoice.contents) {
when (content) {
is Content.Text -> println("text: ${content.text}")
is Content.Reasoning -> println("reasoning: ${content.value}")
is Content.ToolCall -> println("toolCall: ${content.name} ${content.argumentsJson}")
is Content.Parts -> println("parts: ${content.parts}")
}
}
}Content copied to clipboard
Constructors
Link copied to clipboard
constructor(id: String, obj: String, created: Long, model: String, choices: List<OpenAIChoice>, usage: OpenAIUsage? = null, systemFingerprint: String? = null, serviceTier: OpenAIServiceTier? = null)
Properties
Link copied to clipboard
The list of completion choices.
Link copied to clipboard
The processing tier actually used to serve the request. May differ from the requested tier. null if not included.
Link copied to clipboard
Represents the backend configuration that the model runs with. Can be used in conjunction with the seed request parameter to understand when backend changes impact determinism. null if not included.
Link copied to clipboard
Token usage statistics. null if not included.
Functions
Link copied to clipboard
Link copied to clipboard
Converts this response to a provider-agnostic ChatResponse.