Message Type Overview
SDKAssistantMessage
Contains responses from the AI assistant.Type Definition
Type Guard
Example Usage
Fields
Message type identifier.
Unique identifier for this message.
Session identifier.
API message ID.
Model used to generate this response (e.g.,
'gpt-4', 'qwen-max').Array of content blocks. See Content Blocks below.
Reason why generation stopped:
'end_turn': Normal completion'max_tokens': Token limit reached'stop_sequence': Stop sequence encountered
Token usage information:
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
Whether the query completed with an error.
Result subtype:
'success': Query completed successfully'error_max_turns': Exceeded maximum turns'error_during_execution': Error during execution
Total duration of the query in milliseconds.
Time spent in API calls in milliseconds.
Number of conversation turns executed.
Result message (only present when
is_error is false).Extended usage information including web search requests and cache metrics.
Per-model usage breakdown.
Array of tools that were denied permission during execution.
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 (whenincludePartialMessages: true).
Type Definition
Type Guard
Example Usage
Stream Event Types
Signals the start of a new message:
Signals the start of a new content block:
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 }
Signals completion of a content block:
Signals completion of the entire message:
Content Blocks
Content blocks represent different types of content in messages:TextBlock
ThinkingBlock
ToolUseBlock
ToolResultBlock
Type Guards for Content Blocks
Complete Example
See Also
- query() Function - Create query sessions
- Query Instance Methods - Methods for controlling queries
- Examples - Practical usage examples
