Message Item
@Serializable
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")
}Content copied to clipboard
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
Author of the message.
Link copied to clipboard
Generation state of the item; null on an item the caller built.