CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

SessionUsage cache fields default to 0 when API omits cache data

Open Oliver-ZPLiu opened this issue 6 months ago • 2 comments

Description

When the API response does not include prompt_cache_hit_tokens or prompt_cache_miss_tokens, SessionUsage silently shows cache_creation_input_tokens=0 and cache_read_input_tokens=0.

This is indistinguishable from "zero cache hits/misses." The model then reports "cache hit rate 0%" or "cache miss" as if the data was observed — when in fact the API simply did not report it.

Steps to reproduce

  1. Use a model or response path that omits cache telemetry from the API response
  2. Check session usage: cache fields will show 0 instead of null/unknown
  3. The model may claim "cache hit rate 0%" based on this data

Expected behavior

Cache fields should be null/None when the API did not report them, so consumers can distinguish "zero" from "unknown."

Actual behavior

Cache fields default to 0, which is indistinguishable from a genuine zero.

Oliver-ZPLiu avatar May 10 '26 19:05 Oliver-ZPLiu

Thanks for the report. Could you confirm if this issue still reproduces on the newly released v0.8.27?

Hmbown avatar May 10 '26 21:05 Hmbown

Resolved in v0.8.28 via PR #1392. SessionUsage cache fields now correctly use Option when the API omits cache data.

Hmbown avatar May 11 '26 00:05 Hmbown