OpenAIChatCompletionChunk

@Serializable
data class OpenAIChatCompletionChunk(val id: String, val obj: String, val created: Long, val model: String, val choices: List<OpenAIChunkChoice>, val usage: OpenAIUsage? = null, val systemFingerprint: String? = null, val serviceTier: OpenAIServiceTier? = null) : AIChunk, Mapper<ChatChunk>

A streaming SSE chunk from the OpenAI chat completion API.

When stream_options with include_usage: true is set on the request, an additional chunk is streamed before the data: [DONE] message whose usage field shows the token usage statistics for the entire request and whose choices field is always an empty array.

Example chunk:

{
"id": "chatcmpl-abc123",
"object": "chat.completion.chunk",
"created": 1699892447,
"model": "gpt-5.6-sol",
"choices": [{ "index": 0, "delta": { "content": "Hello" } }]
}

Constructors

Link copied to clipboard
constructor(id: String, obj: String, created: Long, model: String, choices: List<OpenAIChunkChoice>, usage: OpenAIUsage? = null, systemFingerprint: String? = null, serviceTier: OpenAIServiceTier? = null)

Properties

Link copied to clipboard

The streaming choices in this chunk.

Link copied to clipboard

Epoch timestamp.

Link copied to clipboard
val id: String

Unique identifier for this completion.

Link copied to clipboard

The model used.

Link copied to clipboard
@SerialName(value = "object")
val obj: String

Object type (always "chat.completion.chunk").

Link copied to clipboard
@SerialName(value = "service_tier")
val serviceTier: OpenAIServiceTier?

The processing tier actually used to serve the request. null if not included.

Link copied to clipboard
@SerialName(value = "system_fingerprint")
val systemFingerprint: String?

Represents the backend configuration that the model runs with. null if not included.

Link copied to clipboard

Token usage statistics. Only present on the final usage chunk when requested via stream options. null otherwise.

Functions

Link copied to clipboard
open override fun map(): ChatChunk
Link copied to clipboard

Converts this chunk to a core ChatChunk.