29.6 Reading a usage report
- Approved by
- Panaversity ·
In everyday life. A family of five shares one electricity bill. The bill says how many units the house used this month. It does not say whether the water heater or the old fridge used the most. So the eldest son writes down how long each appliance ran, and works out its units. When his total matches the bill, he knows which appliance to fix first. And when his mother asks what one hot meal really costs, he can answer, because he wrote the cooker down on its own line. In this section, the bill is the Console, his notebook is the usage log, and the appliance that used the most is the dominant cost.
What you will learn. You practice this in Lab 29, Task 1.
- What does Dave's headline divide, and by what?
- How do you know which step each call belongs to?
- How do you check your total against the Console?
- Which step is the dominant cost, and how much of its input came from the cache?
- Which change fits the dominant cost?
Why it matters. The bill says what each call cost. Brightline is paid for invoices handled right. A figure that cannot be split by step and by company cannot say where to save, or whether a saving cost Ana anything.
At work. Tuesday, May 11, 2027, 9:00 a.m. Dave's forwarded total for the week is open beside his question (The point). The Console's rows name models and keys. None of them says "extraction", "morning triage" or "Cedar Ridge".
What does the headline divide, and by what?
The week's spend on Brightline's own invoices, divided by the invoices that were handled right. The number on top is what three model steps spent on Brightline's invoices: the extraction, the morning triage and the month-end review. The number below it counts the distinct new invoices that passed the extraction's three gates (Chapter 25) and appeared in a posted 7:10 report. "Distinct" means an invoice extracted twice is counted once. This book calls one result that passed its step's checks an accepted result. The headline is the cost per accepted result of the whole worker.
Under the headline, each model step has a row of its own, because each step's own check decides what it accepted. A step's cost per accepted result is what it spent in the week, divided by the results its check accepted:
| Step | What accepts a result | One accepted result |
|---|---|---|
| The extraction | The three gates: the stop reason, the schema, the values | An invoice that passed all three |
| The morning triage | The check by code of 23.16 | A morning report the check passed |
| The month-end review | Lab 26's check by code (Lab 26) | A review the check passed |
| The suite | Nothing. It measures, and does no work for an invoice | None: "n/a" |
| Ana's questions in the portal | Nothing live (29.3) | None: "n/a" |
The last two rows still show their spend, so nothing is hidden.
A result stopped at a gate is counted for Ana in the 7:10 report, and never priced (Why it matters). So each step's row shows how many results it stopped, beside the dollars.
How do you know which step each call belongs to?
Your code writes it down, one line per model call, because the Console cannot. The Console groups usage by model, workspace or key. Its programmatic form, the Usage and Cost Analytics API, is in beta. It can group by up to five dimensions, such as model, workspace_id, api_key_id, service_tier or speed.1 None of them is a step of your worker, or a company in your portal.
So each step's code adds one line to the portal's usage log, usage/week.jsonl, after every model call. The line names the step, the company, the model and the time. It also copies the response's usage fields (21.12). Here is the shape of one line, with each count shown as <n>:
{"time": "2027-05-03T06:12:40Z", "step": "extraction", "company": "brightline", "invoice": "INV-8340", "request": 1, "model": "claude-sonnet-5-5", "usage": {"input_tokens": <n>, "cache_creation_input_tokens": <n>, "cache_read_input_tokens": <n>, "output_tokens": <n>}}The morning triage and the month-end review run as hosted sessions, so their lines copy the usage the session reports. Then your code prices each line. Each kind of token has its own price. Here are Claude Sonnet 5.5's prices per million tokens. Input costs $2, a five-minute cache write $2.50, a one-hour cache write $4, a cache read $0.10, and output $10.2 input_tokens counts only the tokens after the last cache breakpoint, so it is the part paid at the full input price.3 Output includes the model's thinking (29.2). Prices change, so the log is priced with the prices copied on the day, and the date goes with them.
How do you check your total against the Console?
Add up the priced log for the week, compare it with the Console's cost for the same days, and give every difference a name. The Console's Usage page exports a CSV by API key and model.4 The analytics API's cost endpoint gives the same in dollars, with an Admin API key.1 Wait before you compare. The analytics data "typically refreshes within 4 hours" and "can take up to 24 hours". Values can still change until about seven days after the month ends.1 On Tuesday, the week that ended on Sunday is in.
Three things explain a gap, and each has a place in the report:
- The lines for Cedar Ridge. Cedar Ridge Supply's invoices run on the same portal, for a fixed monthly fee (23.5). Its calls are in the Console's total and in the log. The log's
companyfield sets them apart. They are not a difference, and they are not in Brightline's headline. - Hosted-session charges. 23.5 says some platforms add charges for the time a session spends running. Your log sees tokens only. Any such charge is the named difference.
- A figure from an SDK. If a step runs on the Claude Agent SDK, its
total_cost_usdfield is a "client-side estimate", "not authoritative billing data". The SDK works it out from a price table built into it.5 Log that step's usage fields and price them yourself, as for every other step.
Which step is the dominant cost, and how much came from the cache?
The dominant cost is the step with the largest spend in the recorded week. Its cache share says how much of its input was read from the cache. Which step it is comes from the week, not from a guess. Sort the step rows by spend, and the top row is the one to work on first.
This book's cache share is the part of a step's input that was read from the cache. It is cache_read_input_tokens divided by the sum of input_tokens, the cache writes and cache_read_input_tokens. The analytics page gives the fields, but names no such measure, so the division is yours.1
Anthropic gives a figure to compare with. Agent loops "read a median 84%" of their input from the cache, and the top tenth read 94% or more. Anthropic adds: "Below about 80%, look for something breaking the cache."6 That figure is for agent loops, where each turn resends a long conversation. Each extraction reads one invoice that no earlier request held, so part of its input can never come from the cache. Read a share under 80% as a reason to look, not as a final answer.
To look, turn on cache diagnostics. Send "diagnostics": {"previous_message_id": null} on the first request, then the previous response's id on the next. The response then says why the cache missed: model_changed, system_changed, tools_changed, messages_changed, or that it could not tell. It reports only the earliest place where the two requests differ. Its cache_missed_input_tokens is an estimate, "a magnitude indicator rather than a billing number".7
At 9:00 your step rows show the extraction as the largest line, with little of its input read from the cache.
Which change fits the dominant cost?
Match the kind of spend to the change that can lower it, then check that change the way it can fail. The usage fields show which kind of spend is large:
| What the step's row shows | The change to try | How it is checked |
|---|---|---|
| Large repeated input, and a low cache share | Cache breakpoints (29.7) | The cache share. The output cannot change |
| Work that nobody waits for | A batch (29.8) | The deadline. The output cannot change |
| Large output or thinking | Lower effort first (29.2), then a smaller tier (29.3) | The step's suite cases, three trials on each model |
The first two change the price or the timing, and leave the text the model reads alone. The third changes the output, so only the suite can say whether it still passes. Which requirement each change must still meet is the step's binding constraint (29.4).
One setting looks like a saving and is not one. A lower max_tokens only cuts answers off, and the tokens already written are still paid (29.2). Section 29.9 sets it.
The operating rule: tag every model call with its step and company, and check the log's total against the Console. Divide each step's spend by the results its check accepted.
Check yourself
Question 1 / 5
0 answered
Dave's headline divides the week's spend on Brightline's own invoices by what?
Sources
- Owner
- Panaversity