Expand description
The one reading of a provider’s usage, for every place srv counts tokens
(docs/specs/SPEC_TOKEN_ANALYSIS_PER_KANBAN_TASK_2026_11_22.md section 4.5): the Audit, the context meter and
the agents translator read through it, and the per-task ledger counts from it.
usage_of takes one output line and returns the call it reports, in six buckets that never overlap: fresh
input, cache read, cache write (5 minutes and 1 hour), output and reasoning. A line that reports no usage, or in a
shape this does not know, returns None: not reported is never zero. Nothing of the line is kept: no text, no
tool input, no path.
Shapes read (the fixtures in usage_of_tests.rs are lines of each):
- Claude stream-json: an
assistantframe, or astream_eventholdingmessage_start;parent_tool_use_id(orisSidechain) marks a subagent’s call. The same call is repeated per content block with the same message id, and onlyoutput_tokensgrows: counting once per message id is the counter’s job. - Codex session file: an
event_msgtoken_count, from itslast_token_usage. Cached tokens are insideinput_tokensthere, so they are taken out of it here. - A model response (a route model’s, through the gateway): a Messages response body, or a
message_startevent of its stream.
A turn’s result line is not a call (its usage is the turn’s sum): turn_total reads that.
Structs§
- Buckets
- What a call used, in buckets that never overlap. The inclusive totals (OpenTelemetry’s
input_tokens) are sums of these. - Call
Usage - One call, as its line reports it.
Enums§
- Call
Kind - Whose call it is.
- Source
- Which shape the line had; a counter of lines it could not read is kept per source, so a provider’s change shows.
Functions§
- buckets_
of - The buckets of an Anthropic-style
usageobject, and whether it reports reasoning apart.Nonewhen it holds none of the four counts: a field that is missing among them is 0, an object with none of them is not a reading. - turn_
total - A turn’s sum, from the
usageof itsresultline. - usage_
of - The call that
linereports, if it reports one. - usage_
of_ value usage_offor a line already parsed.