Skip to content

Align Anthropic usage accounting with provider contract - #617

Open
elrensmin wants to merge 3 commits into
huggingface:mainfrom
elrensmin:fix/anthropic-usage-fresh-input
Open

Align Anthropic usage accounting with provider contract#617
elrensmin wants to merge 3 commits into
huggingface:mainfrom
elrensmin:fix/anthropic-usage-fresh-input

Conversation

@elrensmin

@elrensmin elrensmin commented Aug 19, 2026

Copy link
Copy Markdown

Summary

Align Anthropic streaming usage normalization with the provider's response contract.
Anthropic's input_tokens already excludes tokens read from or written to the
prompt cache, so Tau preserves it as fresh input and reports total input as the
sum of fresh, cache-read, and cache-write tokens.

Changes

  • Preserve Anthropic's provider-reported input_tokens in message_start and
    message_delta.
  • Recompute totals from fresh input, cache reads, cache writes, and output.
  • Keep 1-hour cache-write details and ignore malformed or negative counters.
  • Add independent coverage for delta ordering, partial/repeated updates,
    delta-only usage, zero/null values, and malformed values.

Validation

  • uv run pytest — 1879 passed, 3 skipped
  • uv run ruff check .
  • uv run ruff format --check .
  • uv run mypy
  • Hugo and Pagefind website builds

@alejandro-ao alejandro-ao changed the title Fix Anthropic usage double-counting cache in input Align Anthropic usage accounting with provider contract Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants