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