Class: ClaudeAgentSDK::ResultMessage

Inherits:
Type
  • Object
show all
Defined in:
lib/claude_agent_sdk/types.rb

Overview

Result message with cost and usage information

Instance Attribute Summary collapse

Method Summary

Methods inherited from Type

#[], #[]=, from_hash, #initialize, #to_h, wrap

Constructor Details

This class inherits a constructor from ClaudeAgentSDK::Type

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ClaudeAgentSDK::Type

Instance Attribute Details

#api_error_statusObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def api_error_status
  @api_error_status
end

#deferred_tool_useObject

DeferredToolUse, populated when a PreToolUse hook deferred



498
499
500
# File 'lib/claude_agent_sdk/types.rb', line 498

def deferred_tool_use
  @deferred_tool_use
end

#duration_api_msObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def duration_api_ms
  @duration_api_ms
end

#duration_msObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def duration_ms
  @duration_ms
end

#errorsObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def errors
  @errors
end

#fast_mode_stateObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def fast_mode_state
  @fast_mode_state
end

#is_errorObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def is_error
  @is_error
end

#model_usageObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def model_usage
  @model_usage
end

#num_turnsObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def num_turns
  @num_turns
end

#originHash{Symbol => Object}?

Provenance of the user message that triggered this turn — nil when the CLI did not attribute it. Lets a streaming-input consumer distinguish the result of its own prompt from the result of a turn the session injected on its own:

if result.origin.nil? || result.origin[:kind] == 'human'
  # a turn this application submitted
elsif result.origin[:kind] == 'task-notification'
  # follow-up turn driven by a background task
end

Key form. A plain Hash passed through from the CLI untouched, so its keys are Symbols with the wire spelling preserved — camelCase stays camelCase (origin[:kind], origin[:fromSession], origin[:verifiedPeerPid]), unlike the snake_case attributes elsewhere in this SDK and unlike the Python SDK's string keys. Indexing with origin["kind"] silently returns nil and makes every attributed turn look unattributed.

See UserMessage#origin for the full list of known :kind values and their per-kind keys.

Returns:

  • (Hash{Symbol => Object}, nil)

See Also:



528
529
530
# File 'lib/claude_agent_sdk/types.rb', line 528

def origin
  @origin
end

#permission_denialsObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def permission_denials
  @permission_denials
end

#resultObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def result
  @result
end

#session_idObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def session_id
  @session_id
end

#stop_reasonObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def stop_reason
  @stop_reason
end

#structured_outputObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def structured_output
  @structured_output
end

#subtypeObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def subtype
  @subtype
end

#terminal_reasonObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def terminal_reason
  @terminal_reason
end

#total_cost_usdObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def total_cost_usd
  @total_cost_usd
end

#usageObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def usage
  @usage
end

#uuidObject

model_usage maps model name => per-model usage Hash, passed through verbatim from the CLI's modelUsage field, so its keys are camelCase (matches the TypeScript/Python SDKs' ModelUsage shape): inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, webSearchRequests, costUSD, contextWindow, maxOutputTokens, plus optional canonicalModel (canonical id used for the pricing lookup — may differ from the raw model-string key for provider-specific ids/aliases) and provider ('firstParty', 'bedrock', 'vertex', ...).

terminal_reason says why the query loop ended ("completed", "max_turns", "aborted_streaming", ...). "aborted_streaming" / "aborted_tools" mean the turn was cancelled via Client#interrupt (an interrupt control request). nil when the CLI did not report one (older CLI versions, or a result that bypassed the query loop such as a local slash command).



487
488
489
# File 'lib/claude_agent_sdk/types.rb', line 487

def uuid
  @uuid
end