Skip to main content

Message

Represents a single chat message in a conversation.
id
string
required
Unique identifier for the message
role
'user' | 'assistant' | 'system'
required
The role of the message sender:
  • user: Message from the user
  • assistant: Message from the AI assistant
  • system: System-level instruction or prompt
content
string | MessageContent[]
required
The message content. Can be:
  • A simple string for text-only messages
  • An array of MessageContent objects for multimodal messages (text + images)
timestamp
Date
required
When the message was created
modelId
string
Identifier of the model that generated this message (for assistant messages)
streaming
boolean
Indicates if the message is currently being streamed
imageData
GeneratedImage
Metadata for generated images contained in the message

Example

const message: Message = {
  id: 'msg_123',
  role: 'assistant',
  content: 'Hello! How can I help you today?',
  timestamp: new Date(),
  modelId: 'gpt-4',
  streaming: false
};

MessageContent

Represents individual content blocks within a multimodal message.
type
'text' | 'image_url'
required
The type of content:
  • text: Text content
  • image_url: Image reference
text
string
The text content (when type is 'text')
image_url
object
Image URL configuration (when type is 'image_url')

Example

const multimodalMessage: Message = {
  id: 'msg_456',
  role: 'user',
  content: [
    {
      type: 'text',
      text: 'What is in this image?'
    },
    {
      type: 'image_url',
      image_url: {
        url: 'https://example.com/image.jpg',
        detail: 'high'
      }
    }
  ],
  timestamp: new Date()
};

GeneratedImage

Metadata for AI-generated images.
url
string
required
URL of the generated image
width
number
required
Image width in pixels
height
number
required
Image height in pixels
format
string
required
Image format (e.g., ‘png’, ‘jpg’, ‘webp’)
size
number
required
File size in bytes
prompt
string
required
The prompt used to generate the image
model
string
required
The model used to generate the image
timestamp
Date
required
When the image was generated

Example

const imageData: GeneratedImage = {
  url: 'https://cdn.example.com/generated/abc123.png',
  width: 1024,
  height: 1024,
  format: 'png',
  size: 2048576,
  prompt: 'A serene mountain landscape at sunset',
  model: 'dall-e-3',
  timestamp: new Date()
};

Build docs developers (and LLMs) love