Skip to main content

MessageContent

Multi-modal content types for messages and variables in the Python SDK.

Overview

Content types support text, images, PDFs, tool calls/responses, reasoning, errors, and search results. The MessageContent class is a oneOf union wrapper — the actual content is accessed via the actual_instance property.

MessageContent (Union Type)

Polymorphic content type supporting multiple modalities. Uses actual_instance to hold the concrete content variant.
The actual_instance must be one of: Accessing content:
Type checking:

Text Content

TextContent

See the dedicated TextContent page for full documentation. Plain text content for messages.

Fields

modality
str
required
Must be "text".
value
str
required
The text content string.

Example

JSON:

Image Content

ImageContent

See the dedicated ImageContent page for full documentation. Image content with detail level specification.

Fields

modality
str
required
Must be "image".
detail
str
required
Detail level. One of: "low", "medium", "high", "auto".
value
ImageContentValue
required
Image data — either a URL or base64-encoded content. See ImageContentValue.

ImageContentValue

Union of URL or base64 image content. Use from_dict() to construct.

Example

JSON:

PDF Content

PdfContent

See the dedicated PdfContent page for full documentation. PDF document content with file metadata.

Fields

modality
str
required
Must be "pdf".
value
PdfContentValue
required
PDF data — either a URL or base64-encoded content.
file
PdfContentFile
required
File metadata with name, id, and optional size.

Example

JSON:

Tool Content

ToolCallContent

See the dedicated ToolCallContent page for full documentation. Tool/function call request from LLM.

Fields

modality
str
required
Must be "tool-call".
index
int
required
Zero-based index of the tool call. Minimum: 0.
id
str
required
Unique identifier for this tool call.
name
str
required
Name of the function to call.
arguments
str
required
JSON-encoded string of function arguments.
server_name
str | None
Optional MCP server name. Aliased as serverName in JSON.

Example

JSON:

ToolResponseContent

See the dedicated ToolResponseContent page for full documentation. Tool/function execution response.

Fields

modality
str
required
Must be "tool-response".
index
int
required
Zero-based index matching the tool call. Minimum: 0.
id
str
required
Identifier matching the tool call id.
name
str
required
Name of the function that was called.
data
str
required
JSON-encoded string of the function result.
api_response
ToolResponseContentApiResponse | None
Optional API response metadata with status_code. Aliased as apiResponse in JSON.

Example

JSON:

Reasoning Content

ReasoningContent

See the dedicated ReasoningContent page for full documentation. Reasoning content for chain-of-thought responses.

Fields

modality
str
required
Must be "reasoning".
value
ReasoningContentValueUnion
required
The reasoning value — either a thinking type with content and signature, or a redacted type.

Example


Error Content

ErrorContent

See the dedicated ErrorContent page for full documentation. Error content type for LLM safety and content filtering errors.

Fields

modality
str
required
Must be "error".
value
SafetyErrorContentValue
required
Safety error value with type and value fields.

Example


Search Result Content

SearchResultContent

See the dedicated SearchResultContent page for full documentation. Search result content for grounding LLM responses with web search data.

Fields

modality
str
required
Must be "search-result".
value
SearchResultGoogleContentValue
required
Google search result value with type, references, and responses.

Example


Complete Examples

Multi-Modal Message

Tool Call Flow

Content Filtering