Skip to main content
The Claude Agent SDK uses a structured message system to represent conversations. Messages contain content blocks that represent different types of information.

Message Types

All messages are part of the Message union type:

UserMessage

Represents a message from the user to Claude.
content
str | list[ContentBlock]
required
The message content. Can be a simple string or a list of content blocks.
uuid
str | None
Unique identifier for the message. Only present when extra_args={"replay-user-messages": None} is set in options.
parent_tool_use_id
str | None
ID of the parent tool use if this is a follow-up message within a tool execution context.
tool_use_result
dict[str, Any] | None
Result data if this message is responding to a tool use.

Example

AssistantMessage

Represents a message from Claude (the assistant).
content
list[ContentBlock]
required
List of content blocks (text, thinking, tool use, etc.).
model
str
required
The model used to generate this message (e.g., “claude-sonnet-4-5”).
parent_tool_use_id
str | None
ID of the parent tool use if this message is part of a tool execution.
error
AssistantMessageError | None
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.
subtype
str
required
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
data
dict[str, Any]
required
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.
duration_ms
int
required
Total duration in milliseconds.
duration_api_ms
int
required
API call duration in milliseconds.
is_error
bool
required
Whether the conversation ended with an error.
num_turns
int
required
Number of conversation turns.
session_id
str
required
Session identifier.
stop_reason
str | None
Reason the conversation stopped (e.g., “end_turn”, “max_tokens”).
total_cost_usd
float | None
Total cost in USD.
usage
dict[str, Any] | None
Token usage statistics.
structured_output
Any
Structured output if output_format was specified in options.

Example

StreamEvent

Represents partial message updates during streaming (when include_partial_messages=True).
event
dict[str, Any]
required
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.
text
str
required
The text content.

Example

ThinkingBlock

Represents Claude’s extended thinking process (when thinking is enabled).
thinking
str
required
Claude’s internal reasoning and thought process.
signature
str
required
Signature for the thinking block.

Example

ToolUseBlock

Represents Claude’s intent to use a tool.
id
str
required
Unique identifier for this tool use.
name
str
required
Name of the tool being used (e.g., “Bash”, “Read”, “Write”).
input
dict[str, Any]
required
Input parameters for the tool.

Example

ToolResultBlock

Represents the result of a tool execution.
tool_use_id
str
required
ID of the tool use this result corresponds to.
content
str | list[dict[str, Any]] | None
The result content from the tool execution.
is_error
bool | None
Whether the tool execution resulted in an error.

Example

Complete Example

Type Checking

Use isinstance() 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.