Skip to content

Class: UserMessage

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / 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.

// Simple text message
const msg = new UserMessage('Hello, world!');
// Multimodal message
const msg = new UserMessage([
{ type: 'text', text: 'What is in this image?' },
{ type: 'image', source: { type: 'url', url: '...' }, mimeType: 'image/png' }
]);

new UserMessage(content, options?): UserMessage

Defined in: src/types/messages.ts:231

Creates a new user message.

String (converted to TextBlock) or array of content blocks

string | UserContent[]

MessageOptions

Optional message ID and metadata

UserMessage

Message.constructor

readonly content: UserContent[]

Defined in: src/types/messages.ts:223

Content blocks in this message


readonly id: string

Defined in: src/types/messages.ts:124

Unique message identifier

Message.id


readonly optional metadata: MessageMetadata

Defined in: src/types/messages.ts:130

Provider-specific metadata, namespaced by provider name

Message.metadata


readonly timestamp: Date

Defined in: src/types/messages.ts:127

Timestamp when the message was created

Message.timestamp


readonly type: "user"

Defined in: src/types/messages.ts:220

Message type discriminator

Message.type

get audio(): AudioBlock[]

Defined in: src/types/messages.ts:180

All audio content blocks in this message.

AudioBlock[]

Message.audio


get documents(): DocumentBlock[]

Defined in: src/types/messages.ts:173

All document content blocks in this message.

DocumentBlock[]

Message.documents


get images(): ImageBlock[]

Defined in: src/types/messages.ts:166

All image content blocks in this message.

ImageBlock[]

Message.images


get reasoning(): ReasoningBlock[]

Defined in: src/types/messages.ts:195

All reasoning/thinking content blocks in this message. Available when using extended thinking models.

ReasoningBlock[]

Message.reasoning


get text(): string

Defined in: src/types/messages.ts:156

Concatenated text content from all text blocks. Blocks are joined with double newlines.

string

Message.text


get video(): VideoBlock[]

Defined in: src/types/messages.ts:187

All video content blocks in this message.

VideoBlock[]

Message.video

protected getContent(): ContentBlock[]

Defined in: src/types/messages.ts:240

Returns the content blocks for this message. Implemented by subclasses to provide type-specific content.

ContentBlock[]

Message.getContent