Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Type Alias

ModelMessage

ModelMessage is the AI SDK Core type for conversation messages sent to models. It unifies system, user, assistant, and tool messages, including multimodal content and tool interactions.

How it works

ModelMessage is the common message type accepted by AI SDK Core operations. It is a union of system, user, assistant, and tool messages, with content shapes appropriate to each role; the SDK also exposes a Zod schema for validating the type.

Syntax

type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;

Key points

  • ModelMessage is the fundamental input message structure for AI SDK Core functions.
  • The type covers the message variants accepted in Core functions' messages fields.
  • Use the modelMessageSchema export when runtime Zod validation is needed.
  • SystemModelMessage represents system-level information.
  • UserModelMessage supports text-only content and multimodal text, image, or file content.
  • AssistantModelMessage can represent generated text, tool calls, or both.
  • ToolModelMessage carries results produced by tool calls.

Common mistakes

  • For functions that provide a top-level instructions option, prefer that option rather than putting instructions in a system message.

Example: Define model messages

import { ModelMessage } from 'ai';

const messages: ModelMessage[] = [
  { role: 'system', content: 'You are a helpful assistant.' },
  { role: 'user', content: 'Explain TypeScript generics.' },
  { role: 'assistant', content: 'Generics let types work with a variety of values.' },
];

This creates a typed conversation containing system, user, and assistant messages.

When to use it

Model input

Provide conversation history to generateText or streamText.

Multimodal prompts

Represent multimodal user prompts containing images or files.

Tool workflows

Describe assistant tool calls and subsequent tool results.

  • SystemModelMessage
  • UserModelMessage
  • AssistantModelMessage
  • ToolModelMessage
  • TextPart
  • ImagePart
  • FilePart
  • ToolCallPart

Source: ModelMessage. Checked 2026-10-15.