Message Types
All messages are part of theMessage union type:
UserMessage
Represents a message from the user to Claude.The message content. Can be a simple string or a list of content blocks.
Unique identifier for the message. Only present when
extra_args={"replay-user-messages": None} is set in options.ID of the parent tool use if this is a follow-up message within a tool execution context.
Result data if this message is responding to a tool use.
Example
AssistantMessage
Represents a message from Claude (the assistant).List of content blocks (text, thinking, tool use, etc.).
The model used to generate this message (e.g., “claude-sonnet-4-5”).
ID of the parent tool use if this message is part of a tool execution.
Error type if the message generation failed. Possible values:
"authentication_failed""billing_error""rate_limit""invalid_request""server_error""unknown"
Example
SystemMessage
Represents system-level messages with metadata about the conversation.The type of system message. Common subtypes:
"task_started"- A task has started"task_progress"- Task progress update"task_notification"- Task completion/failure/stopped"mcp_status"- MCP server status"tool_execution"- Tool execution details
Additional data specific to the message subtype.
Specialized System Messages
The SDK provides typed subclasses for common system message subtypes:TaskStartedMessage
TaskProgressMessage
TaskNotificationMessage
Example
ResultMessage
Represents the final result of a conversation with cost and usage information.Total duration in milliseconds.
API call duration in milliseconds.
Whether the conversation ended with an error.
Number of conversation turns.
Session identifier.
Reason the conversation stopped (e.g., “end_turn”, “max_tokens”).
Total cost in USD.
Token usage statistics.
Structured output if
output_format was specified in options.Example
StreamEvent
Represents partial message updates during streaming (wheninclude_partial_messages=True).
Raw Anthropic API stream event (e.g.,
content_block_start, content_block_delta, etc.).Content Blocks
Content blocks represent different types of content within messages.TextBlock
Represents text content from Claude.The text content.
Example
ThinkingBlock
Represents Claude’s extended thinking process (when thinking is enabled).Claude’s internal reasoning and thought process.
Signature for the thinking block.
Example
ToolUseBlock
Represents Claude’s intent to use a tool.Unique identifier for this tool use.
Name of the tool being used (e.g., “Bash”, “Read”, “Write”).
Input parameters for the tool.
Example
ToolResultBlock
Represents the result of a tool execution.ID of the tool use this result corresponds to.
The result content from the tool execution.
Whether the tool execution resulted in an error.
Example
Complete Example
Type Checking
Useisinstance() to check message and content block types:
receive_response() is a convenience method that automatically stops after receiving a ResultMessage. Use receive_messages() for full control over message processing.