Skip to main content
The SDK emits different message types as the query progresses. Each message type provides specific information about the session state, AI responses, and execution results.

Message Type Overview

SDKAssistantMessage

Contains responses from the AI assistant.

Type Definition

Type Guard

Example Usage

Fields

type
'assistant'
Message type identifier.
uuid
string
Unique identifier for this message.
session_id
string
Session identifier.
message.id
string
API message ID.
message.model
string
Model used to generate this response (e.g., 'gpt-4', 'qwen-max').
message.content
ContentBlock[]
Array of content blocks. See Content Blocks below.
message.stop_reason
string | null
Reason why generation stopped:
  • 'end_turn': Normal completion
  • 'max_tokens': Token limit reached
  • 'stop_sequence': Stop sequence encountered
message.usage
Usage
Token usage information:
parent_tool_use_id
string | null
ID of the parent tool use, if this is a response to a tool invocation.

SDKResultMessage

Indicates query completion with success or error information.

Type Definition

Type Guard

Example Usage

Fields

is_error
boolean
Whether the query completed with an error.
subtype
string
Result subtype:
  • 'success': Query completed successfully
  • 'error_max_turns': Exceeded maximum turns
  • 'error_during_execution': Error during execution
duration_ms
number
Total duration of the query in milliseconds.
duration_api_ms
number
Time spent in API calls in milliseconds.
num_turns
number
Number of conversation turns executed.
result
string
Result message (only present when is_error is false).
usage
ExtendedUsage
Extended usage information including web search requests and cache metrics.
modelUsage
Record<string, ModelUsage>
Per-model usage breakdown.
permission_denials
CLIPermissionDenial[]
Array of tools that were denied permission during execution.
error
object
Error information (only present when is_error is true):

SDKSystemMessage

Provides session information and configuration.

Type Definition

Type Guard

Example Usage

SDKUserMessage

Represents a user message sent to the AI.

Type Definition

Type Guard

Example Usage

You typically create these messages when using multi-turn conversations:

SDKPartialAssistantMessage

Streaming events emitted during message generation (when includePartialMessages: true).

Type Definition

Type Guard

Example Usage

Stream Event Types

message_start
MessageStartStreamEvent
Signals the start of a new message:
content_block_start
ContentBlockStartEvent
Signals the start of a new content block:
content_block_delta
ContentBlockDeltaEvent
Incremental update to a content block:
Delta types:
  • { type: 'text_delta', text: string }
  • { type: 'thinking_delta', thinking: string }
  • { type: 'input_json_delta', partial_json: string }
content_block_stop
ContentBlockStopEvent
Signals completion of a content block:
message_stop
MessageStopStreamEvent
Signals completion of the entire message:

Content Blocks

Content blocks represent different types of content in messages:

TextBlock

Plain text content from the assistant.

ThinkingBlock

Internal reasoning/thinking process of the AI.

ToolUseBlock

Represents a tool being invoked.

ToolResultBlock

Result from a tool execution.

Type Guards for Content Blocks

Complete Example

See Also