learningto/pass

Metering & Cost Attribution

AdvancedConcepts

The fourth serving job is the meter: the model serves traffic, the fleet is paid for, and the dollars land on an invoice that says per 1M, in and out, so the interview question becomes who spent what and on whose behalf. The model is one month of one product. Tokens per request are stated per side - a chat assistant sends 800 prompt tokens and writes 300 out, a coding copilot 2,400 and 600, and a research agent 12,000 and 4,000, because an agentic loop re-sends its context after every tool call and produces tool chatter of its own, so the same "request" moves 15x the tokens. Rates are per 1M tokens, priced separately for prompt and output: the fast tier is $0.80 in and $4.00 out, the flagship $3 and $15, the frontier $15 and $75 - and the out-rate is always the 5x side, because output is generated token by token against a weight read that a prompt prefix caches but an answer never does. Three policy lines decide whether the ledger can be trusted. The prefix cache sells the repeated prompt at a tenth of the fresh rate, so the cached share of prompt tokens is the cheapest dollar on the bill and the saved line meters the discount forgone. Retries re-bill the whole request at full price - both sides - so a 20% retry rate is a 17% tax that product analytics never sees, because from the code's point of view nothing changed. Attribution, tagging the bill by named spender, adds no dollars at all, but a bill with no owner is invisible to the chargeback, the margin check, and the anomaly alert, and the sim lets at most 10% of the bill go untagged before it stops being a ledger. The output numbers compound: the blended rate - bill over every token moved - is the one-line answer to "what does this product cost us per use," and the raw bill against the budget line is the one finance reads. Interviewers test this because the meter is where engineering meets accounting: the xAE-style system-design round asks how you would bill two teams sharing one serving pool, and cost-per-request arithmetic shows up under the scaling follow-ups of nearly every AI design question. The three challenges below work the meter: the dollars one request bills, the bill the cached prefix discounts, and the ghost dollars a half-tagged bill leaks.

Key Concepts

  • 1Tokens per request decide the bill before the model does: the same 6M requests bill $523,152 as the research agent on flagship, $85,730 as the copilot, and $38,027 as the chat assistant - a 15x spread from nothing but the request profile, which is why the interview answer prices a product in tokens per request, not requests
  • 2The out-rate is the 5x side of every tier, and output never caches: on the agent profile the output line is $360k of a $498k clean bill, so a 90% prompt-cache discount cannot rescue a bill whose weight sits on the generated side
  • 3The cache line bills the repeated prefix at 10% of the fresh rate: at a 40% hit share the prompt line bills at a 0.64 factor (0.6 fresh + 0.4 x 0.1), and the saved line - the discount forgone - is the first thing to meter when the bill surprises you
  • 4A retry is a second workload you never planned for: it re-bills prompt and output at full price, a 20% rate taxes the bill 17%, and product analytics still report the traffic did not change - only the meter saw the re-billed requests
  • 5Attribution adds no dollars, it names them: the untagged share is real spend with no owner, invisible to chargeback, margin math, and alerts, and past 10% of the bill the ledger stops being a ledger - the fix is a required tag on every metered call, not a hunt for the missing dollars
  • 6The blended rate - bill over every token moved, cached and fresh - is the scale-free price of the product, and the raw bill against the budget line is the accounting check; the two answers disagree on purpose, because rate per use and dollars per month measure different failures

The trade-offs to name out loud

Token-rich features vs the meter

The research agent answers better because it re-reads context and streams tool turns, and every one of those tokens bills: 15x the tokens per request turns a rounding-error feature into the budget line. The design answer is not "use less model" but "price the profile first" - tokens per request, the cached share, and the retry rate decide what a feature costs before the tier does.

Cache hit share vs profile shape

A high prefix-cache hit share is the cheapest dollar on an agent bill, because agent context is mostly re-sent system prompts and prior turns - exactly what a prefix cache sells at a tenth of the rate. But the discount lands only on the prompt side: a profile that writes long answers bills the output line at full price no matter how perfect the cache is, so the cache strategy follows the in/out ratio, not the hype.

Metering discipline vs shipping speed

Attribution is infrastructure: a required tag on every metered call costs a code-review rule and a failing test, while retrofitting tags after the fact means untangling a bill that has already taught finance nothing. Ten unowned percent this month is how a chargeback becomes an argument, and the teams that meter leaks as separate lines (retries, untagged share) catch the anomaly the month it starts.

Read the month's meter bill

The token meter walkthrough

The fleet walkthrough beside this one prices the hardware the tokens run on; this one prices the tokens themselves. The provider invoice reads per 1M, priced separately for prompt and output, and the month's bill follows from four settings and three policy lines. Set the product profile (tokens per request), the tier, the monthly volume, and the budget line; then the meter's levers: how much of the prompt hits the prefix cache, what share of calls retry, and what share of the bill carries a tag. Watch three numbers instead of one: the raw bill against the budget, the blended dollars per 1M tokens, and the two leak lines - retry tax and untagged spend.

The knobs

The workload

Product profile: Chat assistant, 800 in / 300 out

The request profile is the first multiplier: the agent loop moves 15x the tokens of the chat turn, because tool calls re-send context and the answer is a stream of thought.

Model tier: Fast tier: $0.80 in / $4.00 out per 1M

Prompt and output price separately, and output is the 5x side every step. On output-heavy products the out-rate decides the bill; the frontier tier meters exactly what the flagship does, just 5x louder.

The plan

Requests this month: 3000000

Volume multiplies every other leak: a 5% retry rate is a rounding error at 1M calls and a budget line at 12M, and every untagged dollar scales with it.

Monthly AI budget: $25k

The budget line is the sim's ledger floor: it is what finance sees, and the check is the raw bill against it - not a blended rate, a real dollar line at the end of the month.

The meter

Prefix-cache hit share: 40

The cached share of the prompt bills at 10% of the fresh rate. On prompt-heavy products it is the cheapest dollar on the bill; on output-heavy ones it moves a fifth of the line, because output never caches.

Retry rate: 5

A retry re-bills the whole request - both sides, at full price. It is invisible until someone meters it separately, which is why the meter counts it, not the code that caused it.

Tagged share of traffic: 90

Attribution adds no dollars - tagging is what makes the dollars say who they belong to. The untagged share is a real bill with no owner, and it is where margin quietly goes to die.

the month's bill, after a 5% retry re-bill

$5,070

the bill before retries, the clean month

$4,829

of the $25,000 budget line

20.3%

blended per 1M tokens moved: the price of one use

$1.463

prompt spend the cache discounts away at 10% of fresh

$691

untagged spend, a 10.0% share, cap 10%

$507

retry tax: dollars that changed no answer, cap 10%

$241

Where this month's bill came from

Cached prompt (bills at a tenth of the fresh rate)80.64 at 40% hit share
Fresh prompt (full price; the cache's whole upside)1,209.6
Output (always full price; never caches)3,780
cached 1.6% fresh prompt 23.9% output 74.6% bill $5,070, leaks in it: $748 at most (some overlap)
the bill fits the budgetpassthe month bills $5,070 against a $25,000 budget line, 20.3% of it
the bill names its spenderspass10% of the bill carries no tag, inside the 10% cap: chargeback, margin math, and anomaly alerts all read this ledger
retries stay a rounding errorpass5% of calls re-bill in full: 4.8% of the bill is retry tax, inside the 10% cap

The month's ledger

The ledger reads clean: 3,465,000,000 billed tokens cost $5,070, 20.3% of the line, at a blended $1.463 per 1M. The cache bills its share at a tenth, the retry tax is inside its cap, and the untagged share is inside its cap - a bill finance can read and a rate per use you can defend. That is what a trusted ledger sounds like.

Product profile

Chat assistant moves 800 prompt tokens and 300 output tokens per request: 27% of its tokens are billable at the 4.00x side of the meter.

Model tier

Fast tier meters $0.80 per 1M prompt and $4.00 per 1M output: this month's mix bills $80.64 cached, $1,209.6 fresh-prompt, and $3,780 output.

Requests this month

3,000,000 requests this month move 3.46B billed tokens and produce the $5,070 bill: the meter's raw input, everything below is policy on top of it.

Monthly AI budget

The $25,000 budget line takes 20.3% of itself this month: at month's end the check is the raw bill against the line, not a rate, and it is where every other knob's damage lands.

Prefix-cache hit share

40% of prompt tokens bill at 10% of the fresh rate: $691 of prompt spend never happens this month, and the cached share is the first thing to meter when the bill surprises you.

Retry rate

A 5% retry rate re-bills every retried request in full: $241 of this bill changed no answer, and none of it shows up in product analytics - only the meter saw it.

Tagged share of traffic

90% of the bill is tagged to a named spender; the $507 it misses is real spend with no owner, invisible to chargeback, margin, and alerts alike.

Mattered vs noise (which knobs actually moved the bill)

Product profile: matteredModel tier: matteredRequests this month: matteredMonthly AI budget: noisePrefix-cache hit share: matteredRetry rate: matteredTagged share of traffic: mattered

Load a famous metered bill, then fix the plan yourself

The profiles and the tier rate cards (per 1M tokens)

Chat assistant: 800 in / 300 outCoding copilot: 2,400 in / 600 outResearch agent: 12,000 in / 4,000 outFast tier: $0.80 in, $4.00 outFlagship tier: $3.00 in, $15.00 outFrontier tier: $15.00 in, $75.00 out

Python Implementation

example.py
Loading...
Now try it yourself
3 challenges with test cases and AI feedback
Practice Now

Complexity Analysis

1481216n²nlog n1n (input size)
COMMON OPERATIONS
Array
Access:O(1)
Search:O(n)
Insert end:O(1)*
Insert mid:O(n)
Hash Map
Get/Set:O(1)*
Delete:O(1)*
Search value:O(n)
Iterate:O(n)
Linked List
Access:O(n)
Search:O(n)
Insert head:O(1)
Delete known:O(1)
Binary Search
Search:O(log n)
Insert:O(log n)
Balanced BST
Search:O(log n)
Insert:O(log n)
Delete:O(log n)
Heap
Peek min/max:O(1)
Push:O(log n)
Pop:O(log n)
Heapify:O(n)
Graph (BFS/DFS)
Traversal:O(V+E)
Dijkstra (heap):O((V+E) log V)
Merge / Quick Sort
Sort:O(n log n)
Space (merge):O(n)
Space (quick):O(log n)

* amortized average case

READY TO TEST YOURSELF?

Put Metering & Cost Attribution into practice

The best way to lock in what you've learned is to write code. Solve real interview-style problems right now.

Lock in $4.99/mo forever

Joining the founding waitlist locks the $4.99/mo founding price for you, at the lowest price we will ever run. First 100 members. No payment now.

One email about the founding offer and the launch. No spam, unsubscribe anytime.
Metering & Cost Attribution
Next: Fleet Efficiency & Eviction