Parse Claude token usage and estimate cost
The Anthropic Usage Stats Parser reads the usage object from a Claude
Messages API response and breaks out every token category Anthropic bills
separately: regular input, output, cache-creation (writes), and cache-read
(hits). It then estimates the dollar cost using the correct rate for each
category. No API key is required — you are parsing a response you already have.
How it works
The tool parses your JSON and reads:
usage.input_tokens— tokens from regular (non-cached) inputusage.output_tokens— tokens in the model’s responseusage.cache_creation_input_tokens— tokens written into the prompt cache on this callusage.cache_read_input_tokens— tokens read back from cache (not re-processed)
Anthropic bills these at different rates: cache writes cost 1.25× the base input price (you pay a small premium to create the cache entry), while cache reads cost only 0.1× (a 90% discount on repeated long prompts). The estimate multiplies each bucket by the right per-million-token price for the model you select, then sums them. Everything runs locally.
Understanding what the usage object looks like
A typical Anthropic Messages API response includes a top-level usage key:
{
"usage": {
"input_tokens": 1842,
"output_tokens": 312,
"cache_creation_input_tokens": 1024,
"cache_read_input_tokens": 0
}
}
On the first call with prompt caching enabled, you see cache_creation_input_tokens
greater than zero. On subsequent calls with the same cached content, you see
cache_read_input_tokens greater than zero and input_tokens reduced — the cached
portion is not re-billed at the full input rate.
Diagnosing prompt-caching behaviour
Healthy caching pattern:
- First call:
cache_creation > 0,cache_read = 0 - Second and later calls:
cache_read > 0,cache_creation = 0
Cache misses on every call:
- All calls show
cache_creation > 0andcache_read = 0 - This means the cache is not being hit — check that your cache breakpoints are placed at stable content before any variable content, and that the TTL has not expired between calls.
Higher-than-expected cost:
- Cache writes (1.25× rate) on a huge system prompt add up if the TTL expires frequently between calls. Cache TTL in Anthropic’s system is typically around 5 minutes for short prompts and longer for large documents, but exact TTL depends on usage patterns.
Comparing providers with this tool
The Anthropic billing model is structured differently from OpenAI’s. OpenAI Cached Input Tokens are billed at a 50% discount on repeated prefix content. Anthropic’s cache reads are at a 90% discount. Use both parsers side-by-side to compare actual cost per call when evaluating which provider is cheaper for your specific prompt structure. Nothing you paste leaves your browser.