Cost - patrickbykov/claude-telemetry-widget GitHub Wiki

Cost

TL;DR: Each request is priced as 4 parts: fresh input, output, cache read and cache write. Cache writes cost extra: 1.25× input for a 5-minute entry, 2× for a 1-hour entry. (D)

Formula

From pricing.py: parts(). Prices are per million tokens.

fresh = inp * price_in
out   = out * price_out
read  = cr  * price_read
write = (c5 * 1.25 + c1 * 2.0) * price_in

cost  = fresh + out + read + write
Field Meaning
inp Fresh input tokens (not from cache)
out Output tokens
cr Tokens read from the cache (cheap)
c5 Tokens written to the 5-minute cache
c1 Tokens written to the 1-hour cache

Worked example

Opus 5.5 pricing: in $4, out $20, read $0.20.

Part Tokens Calculation Cost
fresh 2,000 2,000 × 4 / 1M $0.008
read 140,000 140,000 × 0.20 / 1M $0.028
write (1h) 8,000 8,000 × 2.0 × 4 / 1M $0.064
out 1,500 1,500 × 20 / 1M $0.030
total $0.130

Note: the cache read covered 140k tokens for $0.028. The same tokens as fresh input would cost $0.56, which is 20× more. That's why a warm cache matters.

How the price is chosen

  1. Each key in prices.json is matched against the model id on - boundaries.
  2. The longest match wins. claude-opus-5-5 matches both opus-5 and opus-5-5, so it gets opus-5-5.
  3. If nothing matches, the default price is used.

Cache hit rate

Shown as "cache hit %" in the menu:

hit = cr / (inp + cr + c5 + c1)

Today's hit rate is flagged when it is below 85% (warn_cache_hit_below).


Next: Context and cost threshold →