Skip to content

feat(usage): cache_read_tokens and cache_write_tokens on usage events - #21

Merged
coyl merged 2 commits into
mainfrom
feat/cache-tokens
Oct 23, 2026
Merged

coyl merged 2 commits into
mainfrom
feat/cache-tokens

Conversation

@coyl

@coyl coyl commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Part of ai-process/docs#78 (prompt-cache costs in KTMS).

  • usage.v1: UsageEvent.cache_read_tokens = 17, cache_write_tokens = 18; summed in UsageSummaryRow (16, 17) and UsageByMetaRow (9, 10). Additive; buf breaking passes.
  • Both are part of tokens_input; an event is refused if either is negative or together they exceed it.
  • Postgres migration 008 and ClickHouse migration 004 add the columns (default 0); insert, COPY, outbox, replicator and both read paths carry them. HTTP accepts and returns them.
  • Tests: Postgres InsertOne/InsertBatch and summaries, outbox round trip, Postgres vs ClickHouse totals, proto validation.

KTMS fills them after this lands (its CI checks usage.proto against this repo's main).

coyl added 2 commits October 23, 2026 17:02
The input tokens read from and written to the vendor's prompt cache, part of
tokens_input, so callers and reports can tell cached input from plain input
that vendors bill at a different rate. Stored in Postgres and ClickHouse and
summed in summary and by-meta rows.
…ClickHouse and HTTP

Events without cache tokens validate exactly as before, and the bound check
cannot overflow. Tests cover cache_write_tokens through the replicator and
both ClickHouse reads, and the HTTP mapping. The README says how to report
Anthropic usage, whose input_tokens excludes cached input.
@coyl
coyl merged commit e81c516 into main Oct 23, 2026
5 checks passed
@coyl
coyl deleted the feat/cache-tokens branch October 23, 2026 15:10
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.

1 participant