anthropics / anthropics/claude-agent-sdk-typescript

Discrepancies between usage and modelUsage in result messages

Open
#112 0 comments 4 reactions 0 assignees View on GitHub
bug question
Dominant language
Shell
Stars
1.8k
Forks
226
PR merge metrics
No merged PRs in 30d

Description

Hi there!

I am having issues understanding the difference between `usage` and `modelUsage` fields in the `SDKResultMessage`.

My understandings:
- `usage`: it contains the summary of the token used across the agent run without differentiating among different models
- `modelUsage`: it is a breakdown of the token used across the agent run. A summary for each model used.
- if the agent used only one model the two fields should contain the same numbers

The last point is not true as you can see from the following `SDKResultMessage` instance:
```javascript
{
type: 'result',
subtype: 'success',
is_error: false,
duration_ms: 16025,
duration_api_ms: 24144,
num_turns: 9,
result: '...',
session_id: 'd74b87d2-8f7a-4def-8819-2c27e04520a7',
total_cost_usd: 0.1839242,
usage: {
input_tokens: 33,
cache_creation_input_tokens: 53995,
cache_read_input_tokens: 230827,
output_tokens: 904,
server_tool_use: { web_search_requests: 0, web_fetch_requests: 0 },
service_tier: 'standard',
cache_creation: { ephemeral_1h_input_tokens: 0, ephemeral_5m_input_tokens: 53995 }
},
modelUsage: {
'claude-haiku-4-5-20251001': {
inputTokens: 39,
outputTokens: 1284,
cacheReadInputTokens: 230827,
cacheCreationInputTokens: 123506,
webSearchRequests: 0,
costUSD: 0.1839242,
contextWindow: 200000
}
},
permission_denials: [],
uuid: 'a9e78d3c-1d4c-4bfa-9027-52007d35e5d3'
}
```

Is it a bug or my understandings are wrong?

Moreover, `total_cost_usd` is right if computed with numbers in `modelUsage`. So I assume that `modelUsage` is the authoritative one.

Thanks.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.