了解並追蹤 Claude Code SDK 中用於計費的代幣使用量
id
欄位的訊息報告相同的使用量。當 Claude 在同一輪中發送多個訊息時(例如,文字 + 工具使用),它們共享相同的訊息 ID 和使用量資料。
result
訊息包含對話中所有步驟的總累積使用量:
output_tokens
值。當發生這種情況時:
total_cost_usd
是權威的input_tokens
:處理的基本輸入代幣output_tokens
:回應中產生的代幣cache_creation_input_tokens
:用於建立快取項目的代幣cache_read_input_tokens
:從快取讀取的代幣service_tier
:使用的服務層級(例如,“standard”)total_cost_usd
:以美元計的總成本(僅在結果訊息中)