Content

@Serializable
sealed interface Content

Sealed interface hierarchy modeling all possible content in chat messages.

Content is divided into three sub-hierarchies:

  • Request — Content that can be sent to a model (Text, Parts, ToolCall, ToolResult).

  • Response — Content received from a model (Text, Parts, ToolCall, Reasoning).

  • StreamResponse — Content arriving in streaming chunks (Text, ToolCallDelta, Reasoning).

The concrete types are:

  • Text — Plain text content.

  • ToolCall — A tool invocation requested by the model.

  • ToolCallDelta — An incremental streaming tool call chunk.

  • ToolResult — The result of executing a tool.

  • Reasoning — Model reasoning/thinking content.

  • Parts — Multi-part content (text + images).

Samples

// Create a message with text content.
val message = Message(
    role = Role.User,
    content = Content.Text("Hello, how are you?")
)
// Working with Content.Response:
when (contentResponse) {
    is Content.Parts -> println("Parts: ${contentResponse.parts}")
    is Content.Reasoning -> println("Reasoning: ${contentResponse.value}")
    is Content.Text -> println("Output: ${contentResponse.text}")
    is Content.ToolCall -> println("Tool call: ${contentResponse.name} with ${contentResponse.argumentsJson}")
}

Inheritors

Types

Link copied to clipboard
@SerialName(value = "parts")
@Serializable
data class Parts(val parts: List<ContentPart>) : Content, Content.Request, Content.Response

Multi-part content containing a list of ContentPart items.

Link copied to clipboard
@SerialName(value = "reasoning")
@Serializable
data class Reasoning(val value: String) : Content.Response, Content.StreamResponse

Model reasoning/thinking content.

Link copied to clipboard
@Serializable
sealed interface Request : Content

Content that can be sent to a model in a request.

Link copied to clipboard
@Serializable
sealed interface Response : Content

Content received from a model in a response.

Link copied to clipboard
@Serializable
sealed interface StreamResponse

Content arriving in streaming chunks.

Link copied to clipboard
@SerialName(value = "text")
@Serializable
data class Text(val text: String) : Content, Content.Request, Content.Response, Content.StreamResponse

Plain text content.

Link copied to clipboard
@SerialName(value = "tool_call")
@Serializable
data class ToolCall(val id: String, val name: String, val argumentsJson: String) : Content.Response, Content.Request

A tool invocation requested by the model.

Link copied to clipboard
data class ToolCallDelta(val index: Int, val id: String? = null, val name: String? = null, val argumentsChunk: String? = null) : Content.StreamResponse

An incremental streaming tool call chunk.

Link copied to clipboard
@SerialName(value = "tool_result")
@Serializable
data class ToolResult(val toolCallId: String, val name: String, val content: String) : Content.Request

The result of executing a tool, sent back to the model.