Skip to content
EN DE

UI Messages vs Model Messages

AI SDK v6 uses two distinct message types for different purposes. UIMessage is the source of truth for your application state and powers the frontend via useChat. ModelMessage (also called CoreMessage) is the format that gets sent to the LLM provider.

UIMessage carries rich UI data: an id, a role, an array of typed parts (text, tool invocations, sources, files, reasoning, data), and optional metadata. ModelMessage is leaner and provider-oriented, with role values that include 'tool' and content that varies by role.

You convert between the two with convertToModelMessages() (async, UIMessage to ModelMessage) and convertToUIMessages() (ModelMessage to UIMessage). This separation keeps your UI flexible without polluting what the LLM sees.

interface UIMessage<METADATA = unknown> {
id: string;
role: 'system' | 'user' | 'assistant';
parts: Array<UIMessagePart>;
metadata?: METADATA;
}
// UIMessagePart variants:
// TextUIPart | ToolUIPart | SourceUrlUIPart | FileUIPart
// | StepStartUIPart | ReasoningUIPart | DataUIPart
// ModelMessage (CoreMessage) — role determines content shape
type ModelMessage =
| { role: 'system'; content: string }
| { role: 'user'; content: string | Array<UserContentPart> }
| { role: 'assistant'; content: string | Array<AssistantContentPart> }
| { role: 'tool'; content: Array<ToolResultPart> };
import { convertToModelMessages } from '@ai-sdk/ui-utils';
import { streamText } from 'ai';
// UIMessage[] -> ModelMessage[] (async)
const modelMessages = await convertToModelMessages(uiMessages);
const result = streamText({
model,
messages: modelMessages,
});
import { convertToUIMessages } from '@ai-sdk/ui-utils';
// ModelMessage[] -> UIMessage[]
const uiMessages = convertToUIMessages(modelMessages);
AspectUIMessageModelMessage (CoreMessage)
Used inFrontend (useChat)LLM calls (generateText, streamText)
Rolessystem, user, assistantsystem, user, assistant, tool
Contentparts array (typed)Varies by role (string or content parts)
Has idYesNo
Has metadataYesNo
Source of truth forApp/UI stateProvider communication

Part of AI Learning — free courses from prompt to production. Jan on LinkedIn