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

Example

AssistantMessage

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

Example

StreamEvent

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

Example

ThinkingBlock

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

Example

ToolUseBlock

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

Example

ToolResultBlock

Represents the result of a tool execution.
str
required
ID of the tool use this result corresponds to.
str | list[dict[str, Any]] | None
The result content from the tool execution.
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.