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. TheMessageContent 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. Usesactual_instance to hold the concrete content variant.
actual_instance must be one of:
Accessing content:
Text Content
TextContent
See the dedicated TextContent page for full documentation. Plain text content for messages.Fields
Must be
"text".The text content string.
Example
Image Content
ImageContent
See the dedicated ImageContent page for full documentation. Image content with detail level specification.Fields
Must be
"image".Detail level. One of:
"low", "medium", "high", "auto".Image data — either a URL or base64-encoded content. See ImageContentValue.
ImageContentValue
Union of URL or base64 image content. Usefrom_dict() to construct.
Example
PDF Content
PdfContent
See the dedicated PdfContent page for full documentation. PDF document content with file metadata.Fields
Must be
"pdf".PDF data — either a URL or base64-encoded content.
File metadata with
name, id, and optional size.Example
Tool Content
ToolCallContent
See the dedicated ToolCallContent page for full documentation. Tool/function call request from LLM.Fields
Must be
"tool-call".Zero-based index of the tool call. Minimum: 0.
Unique identifier for this tool call.
Name of the function to call.
JSON-encoded string of function arguments.
Optional MCP server name. Aliased as
serverName in JSON.Example
ToolResponseContent
See the dedicated ToolResponseContent page for full documentation. Tool/function execution response.Fields
Must be
"tool-response".Zero-based index matching the tool call. Minimum: 0.
Identifier matching the tool call
id.Name of the function that was called.
JSON-encoded string of the function result.
Optional API response metadata with
status_code. Aliased as apiResponse in JSON.Example
Reasoning Content
ReasoningContent
See the dedicated ReasoningContent page for full documentation. Reasoning content for chain-of-thought responses.Fields
Must be
"reasoning".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
Must be
"error".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
Must be
"search-result".Google search result value with
type, references, and responses.