Message Types
Complete reference for all WebSocket message types.Outgoing Messages (Client → Server)
init
Initialize a session with configuration options.| Field | Type | Required | Description |
|---|---|---|---|
model | string | No | Claude model (default: from token) |
systemPrompt | string | No | System prompt |
maxTurns | number | No | Max conversation turns |
tools | array | No | Tool definitions |
mcpServers | array | No | MCP server definitions |
allowedTools | string[] | No | Tool whitelist |
disallowedTools | string[] | No | Tool blacklist |
maxBudgetUsd | number | No | Session budget limit |
prompt
Send a one-shot prompt (stateless mode).| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | The prompt message |
model | string | No | Override model |
systemPrompt | string | No | System prompt |
tools | array | No | Tool definitions |
outputFormat | object | No | Structured output format |
sdk_message
Send a message in an active session.| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Message type (user) |
message | string | Yes | User message content |
tool_result
Return a tool execution result.| Field | Type | Required | Description |
|---|---|---|---|
callId | string | Yes | Tool call ID from tool_call |
result | object | Yes | Tool result |
result.content | array | Yes | Content blocks |
result.isError | boolean | No | Whether result is an error |
control
Send control commands.| Action | Description |
|---|---|
close | Gracefully close the session |
ping
Keep-alive ping.Incoming Messages (Server → Client)
control
Server control messages.| Action | Description |
|---|---|
ready | Session initialized and ready |
session_info | Session metadata |
sdk_message
Streaming response content.| Subtype | Description |
|---|---|
text | Text content chunk |
thinking | Extended thinking content |
tool_use | Tool invocation |
tool_call
Request tool execution from client.| Field | Type | Description |
|---|---|---|
id | string | Unique call ID |
name | string | Tool name |
input | object | Tool input arguments |
result
Final response result.| Field | Type | Description |
|---|---|---|
type | string | Always "result" |
subtype | string | success, error, or interrupted |
text | string | Final response text |
total_cost_usd | number | Total cost in USD |
duration_secs | number | Response time |
session_id | string | Session ID for resumption |
usage | object | Token usage details |
error
Error message.| Field | Type | Description |
|---|---|---|
code | string | Error code |
message | string | Human-readable message |
details | object | Additional context |