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
str
required
Must be
"text".str
required
The text content string.
Example
Image Content
ImageContent
See the dedicated ImageContent page for full documentation. Image content with detail level specification.Fields
str
required
Must be
"image".str
required
Detail level. One of:
"low", "medium", "high", "auto".ImageContentValue
required
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
str
required
Must be
"pdf".PdfContentValue
required
PDF data — either a URL or base64-encoded content.
PdfContentFile
required
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
str
required
Must be
"tool-call".int
required
Zero-based index of the tool call. Minimum: 0.
str
required
Unique identifier for this tool call.
str
required
Name of the function to call.
str
required
JSON-encoded string of function arguments.
str | None
Optional MCP server name. Aliased as
serverName in JSON.Example
ToolResponseContent
See the dedicated ToolResponseContent page for full documentation. Tool/function execution response.Fields
str
required
Must be
"tool-response".int
required
Zero-based index matching the tool call. Minimum: 0.
str
required
Identifier matching the tool call
id.str
required
Name of the function that was called.
str
required
JSON-encoded string of the function result.
ToolResponseContentApiResponse | None
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
str
required
Must be
"reasoning".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
str
required
Must be
"error".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
str
required
Must be
"search-result".SearchResultGoogleContentValue
required
Google search result value with
type, references, and responses.