Understand and track token usage for billing in the Claude Code SDK
id
field report identical usage. When Claude sends multiple messages in the same turn (e.g., text + tool uses), they share the same message ID and usage data.
result
message contains the total cumulative usage from all steps in the conversation:
output_tokens
values for messages with the same ID. When this occurs:
total_cost_usd
in the result message is authoritativeinput_tokens
: Base input tokens processedoutput_tokens
: Tokens generated in the responsecache_creation_input_tokens
: Tokens used to create cache entriescache_read_input_tokens
: Tokens read from cacheservice_tier
: The service tier used (e.g., “standard”)total_cost_usd
: Total cost in USD (only in result message)