📄 ai-sdk/docs/reference/ai-sdk-core/model-message

File: model-message.md | Updated: 11/15/2025

Source: https://ai-sdk.dev/docs/reference/ai-sdk-core/model-message

AI SDK

Menu

v5 (Latest)

AI SDK 5.x

AI SDK by Vercel

AI SDK 6 Beta

Foundations

Overview

Providers and Models

Prompts

Tools

Streaming

Getting Started

Navigating the Library

Next.js App Router

Next.js Pages Router

Svelte

Vue.js (Nuxt)

Node.js

Expo

Agents

Agents

Building Agents

Workflow Patterns

Loop Control

AI SDK Core

Overview

Generating Text

Generating Structured Data

Tool Calling

Model Context Protocol (MCP) Tools

Prompt Engineering

Settings

Embeddings

Image Generation

Transcription

Speech

Language Model Middleware

Provider & Model Management

Error Handling

Testing

Telemetry

AI SDK UI

Overview

Chatbot

Chatbot Message Persistence

Chatbot Resume Streams

Chatbot Tool Usage

Generative User Interfaces

Completion

Object Generation

Streaming Custom Data

Error Handling

Transport

Reading UIMessage Streams

Message Metadata

Stream Protocols

AI SDK RSC

Advanced

Reference

AI SDK Core

generateText

streamText

generateObject

streamObject

embed

embedMany

generateImage

transcribe

generateSpeech

tool

dynamicTool

experimental_createMCPClient

Experimental_StdioMCPTransport

jsonSchema

zodSchema

valibotSchema

ModelMessage

UIMessage

validateUIMessages

safeValidateUIMessages

createProviderRegistry

customProvider

cosineSimilarity

wrapLanguageModel

LanguageModelV2Middleware

extractReasoningMiddleware

simulateStreamingMiddleware

defaultSettingsMiddleware

stepCountIs

hasToolCall

simulateReadableStream

smoothStream

generateId

createIdGenerator

AI SDK UI

AI SDK RSC

Stream Helpers

AI SDK Errors

Migration Guides

Troubleshooting

Copy markdown

ModelMessage

===========================================================================================

ModelMessage represents the fundamental message structure used with AI SDK Core functions. It encompasses various message types that can be used in the messages field of any AI SDK Core functions.

You can access the Zod schema for ModelMessage with the modelMessageSchema export.

ModelMessage Types


SystemModelMessage

A system message that can contain system information.

type SystemModelMessage = {  role: 'system';  content: string;};

You can access the Zod schema for SystemModelMessage with the systemModelMessageSchema export.

Using the "system" property instead of a system message is recommended to enhance resilience against prompt injection attacks.

UserModelMessage

A user message that can contain text or a combination of text, images, and files.

type UserModelMessage = {  role: 'user';  content: UserContent;};
type UserContent = string | Array<TextPart | ImagePart | FilePart>;

You can access the Zod schema for UserModelMessage with the userModelMessageSchema export.

AssistantModelMessage

An assistant message that can contain text, tool calls, or a combination of both.

type AssistantModelMessage = {  role: 'assistant';  content: AssistantContent;};
type AssistantContent = string | Array<TextPart | ToolCallPart>;

You can access the Zod schema for AssistantModelMessage with the assistantModelMessageSchema export.

ToolModelMessage

A tool message that contains the result of one or more tool calls.

type ToolModelMessage = {  role: 'tool';  content: ToolContent;};
type ToolContent = Array<ToolResultPart>;

You can access the Zod schema for ToolModelMessage with the toolModelMessageSchema export.

ModelMessage Parts


TextPart

Represents a text content part of a prompt. It contains a string of text.

export interface TextPart {  type: 'text';  /**   * The text content.   */  text: string;}

ImagePart

Represents an image part in a user message.

export interface ImagePart {  type: 'image';
  /**   * Image data. Can either be:   * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer   * - URL: a URL that points to the image   */  image: DataContent | URL;
  /**   * Optional IANA media type of the image.   * We recommend leaving this out as it will be detected automatically.   */  mediaType?: string;}

FilePart

Represents an file part in a user message.

export interface FilePart {  type: 'file';
  /**   * File data. Can either be:   * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer   * - URL: a URL that points to the file   */  data: DataContent | URL;
  /**   * Optional filename of the file.   */  filename?: string;
  /**   * IANA media type of the file.   */  mediaType: string;}

ToolCallPart

Represents a tool call content part of a prompt, typically generated by the AI model.

export interface ToolCallPart {  type: 'tool-call';
  /**   * ID of the tool call. This ID is used to match the tool call with the tool result.   */  toolCallId: string;
  /**   * Name of the tool that is being called.   */  toolName: string;
  /**   * Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.   */  args: unknown;}

ToolResultPart

Represents the result of a tool call in a tool message.

export interface ToolResultPart {  type: 'tool-result';
  /**   * ID of the tool call that this result is associated with.   */  toolCallId: string;
  /**   * Name of the tool that generated this result.   */  toolName: string;
  /**   * Result of the tool call. This is a JSON-serializable object.   */  output: LanguageModelV2ToolResultOutput;
  /**  Additional provider-specific metadata. They are passed through  to the provider from the AI SDK and enable provider-specific  functionality that can be fully encapsulated in the provider.  */  providerOptions?: ProviderOptions;}

LanguageModelV2ToolResultOutput

export type LanguageModelV2ToolResultOutput =  | { type: 'text'; value: string }  | { type: 'json'; value: JSONValue }  | { type: 'error-text'; value: string }  | { type: 'error-json'; value: JSONValue }  | {      type: 'content';      value: Array<        | {            type: 'text';
            /**          Text content.            */            text: string;          }        | {            type: 'media';
            /**          Base-64 encoded media data.            */            data: string;
            /**          IANA media type.          @see https://www.iana.org/assignments/media-types/media-types.xhtml            */            mediaType: string;          }      >;    };

On this page

ModelMessage

ModelMessage Types

SystemModelMessage

UserModelMessage

AssistantModelMessage

ToolModelMessage

ModelMessage Parts

TextPart

ImagePart

FilePart

ToolCallPart

ToolResultPart

LanguageModelV2ToolResultOutput

Deploy and Scale AI Apps with Vercel.

Vercel delivers the infrastructure and developer experience you need to ship reliable AI-powered applications at scale.

Trusted by industry leaders:

  • OpenAI
  • Photoroom
  • leonardo-ai Logoleonardo-ai Logo
  • zapier Logozapier Logo

Talk to an expert