Response Stream Event
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 -> {}
}
}Content copied to clipboard
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.