Class: UserMessage
@providerprotocol/ai / @providerprotocol/ai / UserMessage
Class: UserMessage
Section titled “Class: UserMessage”Defined in: src/types/messages.ts:218
User input message.
Represents a message from the user, which can contain text and/or multimodal content like images, audio, or video.
Example
Section titled “Example”// Simple text messageconst msg = new UserMessage('Hello, world!');
// Multimodal messageconst msg = new UserMessage([ { type: 'text', text: 'What is in this image?' }, { type: 'image', source: { type: 'url', url: '...' }, mimeType: 'image/png' }]);Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new UserMessage(
content,options?):UserMessage
Defined in: src/types/messages.ts:231
Creates a new user message.
Parameters
Section titled “Parameters”content
Section titled “content”String (converted to TextBlock) or array of content blocks
string | UserContent[]
options?
Section titled “options?”Optional message ID and metadata
Returns
Section titled “Returns”UserMessage
Overrides
Section titled “Overrides”Properties
Section titled “Properties”content
Section titled “content”
readonlycontent:UserContent[]
Defined in: src/types/messages.ts:223
Content blocks in this message
readonlyid:string
Defined in: src/types/messages.ts:124
Unique message identifier
Inherited from
Section titled “Inherited from”metadata?
Section titled “metadata?”
readonlyoptionalmetadata:MessageMetadata
Defined in: src/types/messages.ts:130
Provider-specific metadata, namespaced by provider name
Inherited from
Section titled “Inherited from”timestamp
Section titled “timestamp”
readonlytimestamp:Date
Defined in: src/types/messages.ts:127
Timestamp when the message was created
Inherited from
Section titled “Inherited from”
readonlytype:"user"
Defined in: src/types/messages.ts:220
Message type discriminator
Overrides
Section titled “Overrides”Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get audio():
AudioBlock[]
Defined in: src/types/messages.ts:180
All audio content blocks in this message.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”documents
Section titled “documents”Get Signature
Section titled “Get Signature”get documents():
DocumentBlock[]
Defined in: src/types/messages.ts:173
All document content blocks in this message.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”images
Section titled “images”Get Signature
Section titled “Get Signature”get images():
ImageBlock[]
Defined in: src/types/messages.ts:166
All image content blocks in this message.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”reasoning
Section titled “reasoning”Get Signature
Section titled “Get Signature”get reasoning():
ReasoningBlock[]
Defined in: src/types/messages.ts:195
All reasoning/thinking content blocks in this message. Available when using extended thinking models.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get text():
string
Defined in: src/types/messages.ts:156
Concatenated text content from all text blocks. Blocks are joined with double newlines.
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get video():
VideoBlock[]
Defined in: src/types/messages.ts:187
All video content blocks in this message.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”getContent()
Section titled “getContent()”
protectedgetContent():ContentBlock[]
Defined in: src/types/messages.ts:240
Returns the content blocks for this message. Implemented by subclasses to provide type-specific content.