ResponseStreamEvent

@Serializable(with = ResponseStreamEventSerializer::class)
sealed interface ResponseStreamEvent

One semantic server-sent event of a streamed Responses API call.

The Responses API streams a different shape than /chat/completions: instead of chunks that each repeat the whole envelope, it narrates the response as it is assembled — items open and close, content parts open and close, and text arrives as deltas in between. There is no [DONE] marker; the stream ends with ResponseCompletedEvent, ResponseIncompleteEvent or ResponseFailedEvent, each carrying the finished ModelResponse with its usage.

Example:

client.createResponse("Write a haiku").collect { event ->
when (event) {
is OutputTextDeltaEvent -> print(event.delta)
is ResponseCompletedEvent -> println("\n${event.response.usage?.totalTokens} tokens")
else -> {}
}
}

An event the SDK cannot map — an unknown type, or a known one whose payload does not fit — arrives as an UnknownResponseStreamEvent carrying the raw JSON, so one unexpected event never breaks the stream.

See also

Inheritors

Properties

Link copied to clipboard
abstract val sequenceNumber: Int

Position of the event in the stream; increases monotonically.

Link copied to clipboard
abstract val type: String

Raw event type, as sent in the type field.