
# `CoreMessage`

`CoreMessage` 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 `CoreMessage` with the `coreMessageSchema` export.

## `CoreMessage` Types

### `CoreSystemMessage`

A system message that can contain system information.

```typescript
type CoreSystemMessage = {
  role: 'system';
  content: string;
};
```

You can access the Zod schema for `CoreSystemMessage` with the `coreSystemMessageSchema` export.

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

### `CoreUserMessage`

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

```typescript
type CoreUserMessage = {
  role: 'user';
  content: UserContent;
};

type UserContent = string | Array<TextPart | ImagePart | FilePart>;
```

You can access the Zod schema for `CoreUserMessage` with the `coreUserMessageSchema` export.

### `CoreAssistantMessage`

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

```typescript
type CoreAssistantMessage = {
  role: 'assistant';
  content: AssistantContent;
};

type AssistantContent = string | Array<TextPart | ToolCallPart>;
```

You can access the Zod schema for `CoreAssistantMessage` with the `coreAssistantMessageSchema` export.

### `CoreToolMessage`

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

```typescript
type CoreToolMessage = {
  role: 'tool';
  content: ToolContent;
};

type ToolContent = Array<ToolResultPart>;
```

You can access the Zod schema for `CoreToolMessage` with the `coreToolMessageSchema` export.

## `CoreMessage` Parts

### `TextPart`

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

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

### `ImagePart`

Represents an image part in a user message.

```typescript
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 mime type of the image.
   * We recommend leaving this out as it will be detected automatically.
   */
  mimeType?: string;
}
```

### `FilePart`

Represents an file part in a user message.

```typescript
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;

  /**
   * Mime type of the file.
   */
  mimeType: string;
}
```

### `ToolCallPart`

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

```typescript
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.

```typescript
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.
   */
  result: unknown;

  /**
   * Multi-part content of the tool result. Only for tools that support multipart results.
   */
  experimental_content?: ToolResultContent;

  /**
   * Optional flag if the result is an error or an error message.
   */
  isError?: boolean;
}
```

### `ToolResultContent`

```ts
export type ToolResultContent = Array<
  | {
      type: 'text';
      text: string;
    }
  | {
      type: 'image';
      data: string; // base64 encoded png image, e.g. screenshot
      mimeType?: string; // e.g. 'image/png';
    }
>;
```


## Navigation

- [generateText](/v4/docs/reference/ai-sdk-core/generate-text)
- [streamText](/v4/docs/reference/ai-sdk-core/stream-text)
- [generateObject](/v4/docs/reference/ai-sdk-core/generate-object)
- [streamObject](/v4/docs/reference/ai-sdk-core/stream-object)
- [embed](/v4/docs/reference/ai-sdk-core/embed)
- [embedMany](/v4/docs/reference/ai-sdk-core/embed-many)
- [generateImage](/v4/docs/reference/ai-sdk-core/generate-image)
- [transcribe](/v4/docs/reference/ai-sdk-core/transcribe)
- [generateSpeech](/v4/docs/reference/ai-sdk-core/generate-speech)
- [tool](/v4/docs/reference/ai-sdk-core/tool)
- [experimental_createMCPClient](/v4/docs/reference/ai-sdk-core/create-mcp-client)
- [Experimental_StdioMCPTransport](/v4/docs/reference/ai-sdk-core/mcp-stdio-transport)
- [jsonSchema](/v4/docs/reference/ai-sdk-core/json-schema)
- [zodSchema](/v4/docs/reference/ai-sdk-core/zod-schema)
- [valibotSchema](/v4/docs/reference/ai-sdk-core/valibot-schema)
- [CoreMessage](/v4/docs/reference/ai-sdk-core/core-message)
- [createProviderRegistry](/v4/docs/reference/ai-sdk-core/provider-registry)
- [customProvider](/v4/docs/reference/ai-sdk-core/custom-provider)
- [cosineSimilarity](/v4/docs/reference/ai-sdk-core/cosine-similarity)
- [wrapLanguageModel](/v4/docs/reference/ai-sdk-core/wrap-language-model)
- [LanguageModelV1Middleware](/v4/docs/reference/ai-sdk-core/language-model-v1-middleware)
- [extractReasoningMiddleware](/v4/docs/reference/ai-sdk-core/extract-reasoning-middleware)
- [simulateStreamingMiddleware](/v4/docs/reference/ai-sdk-core/simulate-streaming-middleware)
- [defaultSettingsMiddleware](/v4/docs/reference/ai-sdk-core/default-settings-middleware)
- [simulateReadableStream](/v4/docs/reference/ai-sdk-core/simulate-readable-stream)
- [smoothStream](/v4/docs/reference/ai-sdk-core/smooth-stream)
- [generateId](/v4/docs/reference/ai-sdk-core/generate-id)
- [createIdGenerator](/v4/docs/reference/ai-sdk-core/create-id-generator)


[Full Sitemap](/sitemap.md)
