Skip to main content

Overview

The Claude Agent SDK uses strongly-typed message classes to represent conversation turns, system events, and streaming updates.

UserMessage

Represents a message from the user.
content
str | list[ContentBlock]
required
Message content as a string or list of content blocks.
uuid
str | None
Unique message identifier.
parent_tool_use_id
str | None
ID of the parent tool use if this is a tool result message.
tool_use_result
dict[str, Any] | None
Tool result data if this message contains tool output.

Example

AssistantMessage

Represents a response from Claude.
content
list[ContentBlock]
required
List of content blocks (text, thinking, tool use, etc.).See Content Blocks for details.
model
str
required
Model that generated the response (e.g., "claude-sonnet-4-20250514").
parent_tool_use_id
str | None
ID of the parent tool use if this is from a sub-agent.
error
AssistantMessageError | None
Error type if the message failed.
  • "authentication_failed"
  • "billing_error"
  • "rate_limit"
  • "invalid_request"
  • "server_error"
  • "unknown"

Example

SystemMessage

Represents system-level events and metadata.
subtype
str
required
System message type (e.g., "task_started", "task_progress", "task_notification").
data
dict[str, Any]
required
Message-specific data payload.

Task Messages

The SDK provides specialized subclasses for task-related system messages:

Example

ResultMessage

Final result message with cost and usage information.
subtype
str
required
Result type (typically "result").
duration_ms
int
required
Total session duration in milliseconds.
duration_api_ms
int
required
API call duration in milliseconds.
is_error
bool
required
Whether the session ended with an error.
num_turns
int
required
Number of conversation turns.
session_id
str
required
Session identifier.
stop_reason
str | None
Reason for stopping (e.g., "max_turns", "end_turn").
total_cost_usd
float | None
Total cost in USD.
usage
dict[str, Any] | None
Token usage statistics.
result
str | None
Final result text.
structured_output
Any
Structured output if output_format was specified in options.

Example

StreamEvent

Partial message update during streaming (requires include_partial_messages=True).
uuid
str
required
Message UUID being updated.
session_id
str
required
Session identifier.
event
dict[str, Any]
required
Raw Anthropic API stream event data.
parent_tool_use_id
str | None
Parent tool use ID if from a sub-agent.

Example

Session History Types

Types for reading historical session data:

SDKSessionInfo

Returned by list_sessions() with session metadata.

SessionMessage

Returned by get_session_messages() for reading conversation history.