MessageItem

@Serializable
class MessageItem(val role: ResponseRole, val content: ResponseContent?, val id: String? = null, val status: ResponseStatus? = null) : ResponseItem

A message turn: text, or multimodal parts, attributed to a ResponseRole.

Carries either plain text or a list of ResponseContentParts, never both — the two constructors pick the form, and the unused accessor reads back as null.

val plain = MessageItem(ResponseRole.USER, "What is Kotlin?")
val multimodal = MessageItem(
ResponseRole.USER,
listOf(InputTextPart("What is in this image?"), InputImagePart(imageUrl = url)),
)

when (val content = plain.content) {
is ResponseContent.Text -> println(content.text)
is ResponseContent.Parts -> println(content.parts)
null -> println("no content")
}

Constructors

Link copied to clipboard
constructor(role: ResponseRole, content: ResponseContent?, id: String? = null, status: ResponseStatus? = null)
constructor(role: ResponseRole, content: String, id: String? = null, status: ResponseStatus? = null)

Creates a plain-text message item.

constructor(role: ResponseRole, parts: List<ResponseContentPart>, id: String? = null, status: ResponseStatus? = null)

Creates a multimodal message item.

Properties

Link copied to clipboard

Message text or multimodal parts; null only on an item the API sent without any content, such as the empty shell of a response.output_item.added event.

Link copied to clipboard
val id: String?

Identifier the API assigned to the item; null on an item the caller built.

Link copied to clipboard

Author of the message.

Link copied to clipboard

Generation state of the item; null on an item the caller built.

Link copied to clipboard
open override val type: String

Raw type discriminator of the item.

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String