Message class

A single message in the conversation.

Constructors

Message({String? id, required MessageRole role, required List<ContentBlock> content, DateTime? timestamp, StopReason? stopReason, TokenUsage? usage})
Message.assistant(String text)
Create a simple text message from the assistant.
factory
Message.user(String text)
Create a simple text message.
factory

Properties

content List<ContentBlock>
Content blocks containing text, images, or tool interactions.
final
hashCode int
The hash code for this object.
no setterinherited
id String
Unique identifier for this message.
final
role MessageRole
The role of the message sender.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stopReason StopReason?
Why the model stopped generating (assistant messages only).
final
textContent String
Convenience: extract all text from content blocks.
no setter
timestamp DateTime
When this message was created.
final
toolUses List<ToolUseBlock>
Convenience: extract all tool use blocks.
no setter
usage TokenUsage?
Token usage statistics (assistant messages only).
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toApiMap() Map<String, dynamic>
Convert to Anthropic API format.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited