v0.10.5

Usage Normalization

Last updated


How vendor-specific token counters fold into one Usage shape.

The Usage shape


Vendors name token fields differently: the OpenAI family uses prompt_tokens / completion_tokens, Anthropic uses input_tokens / output_tokens, and cache fields diverge further. Usage.UnmarshalJSON folds them into one shape:
  1. type Usage struct {
  2. Input int
  3. Output int
  4. CacheCreate int
  5. CacheRead int
  6. }

Cache accounting


prompt_tokens_details.cached_tokens is subtracted from Input and folded into CacheRead, so a cache hit is never counted twice. Responses-API adapters (input_tokens_details.cached_tokens) and Gemini (cachedContentTokenCount) apply the same subtraction.

中文