ChatMessage

@Serializable
sealed interface ChatMessage

One turn in a chat conversation.

Concrete subtypes — SystemMessage, UserMessage, AssistantMessage, ToolMessage — are distinguished on the wire by the role discriminator.

The MessageBuilder DSL (available via client.chat { ... }) offers shorter syntax for building a list of ChatMessage than instantiating these classes directly.

The interface itself declares no content: the four subtypes disagree on its shape — required text for SystemMessage and ToolMessage, optional text for AssistantMessage, and text or multimodal parts for UserMessage — so each declares its own. Match on the subtype to read it.

Inheritors