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.str | list[ContentBlock]
required
Message content as a string or list of content blocks.
str | None
Unique message identifier.
str | None
ID of the parent tool use if this is a tool result message.
dict[str, Any] | None
Tool result data if this message contains tool output.
Example
AssistantMessage
Represents a response from Claude.list[ContentBlock]
required
List of content blocks (text, thinking, tool use, etc.).See Content Blocks for details.
str
required
Model that generated the response (e.g.,
"claude-sonnet-4-20250514").str | None
ID of the parent tool use if this is from a sub-agent.
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.str
required
System message type (e.g.,
"task_started", "task_progress", "task_notification").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.str
required
Result type (typically
"result").int
required
Total session duration in milliseconds.
int
required
API call duration in milliseconds.
bool
required
Whether the session ended with an error.
int
required
Number of conversation turns.
str
required
Session identifier.
str | None
Reason for stopping (e.g.,
"max_turns", "end_turn").float | None
Total cost in USD.
dict[str, Any] | None
Token usage statistics.
str | None
Final result text.
Any
Structured output if
output_format was specified in options.Example
StreamEvent
Partial message update during streaming (requiresinclude_partial_messages=True).
str
required
Message UUID being updated.
str
required
Session identifier.
dict[str, Any]
required
Raw Anthropic API stream event data.
str | None
Parent tool use ID if from a sub-agent.
Example
Session History Types
Types for reading historical session data:SDKSessionInfo
list_sessions() with session metadata.
SessionMessage
get_session_messages() for reading conversation history.