Metering a REST API is easy to reason about. A call is a discrete event with a predictable cost: it happens or it does not, and counting calls tells you what the customer used. AI infrastructure fails that premise several ways at once. The same input can draw different resources on different runs, the customer’s work spreads across chains of model calls and tool invocations they never directly see, and the cost of one operation can swing by orders of magnitude depending on which model ran and how large the context window was. Metering built for the first picture was never designed for any of the second, let alone all of it together.

Granularity: One Request, Hundreds of Operations

In a traditional API the call is also the unit of work. In an AI product the call only opens the door. What happens behind it is a tree: model completions, retrieval steps, function calls, sub-agent invocations. The customer sends one request; the product may execute dozens to hundreds of operations to answer it.

Meter at the door and you cannot see what actually cost money. Two requests can look identical from outside and consume wildly different compute: one closes in three model calls with short contexts, the other fans out to six sub-agents each holding a long context window. Charging both the same is only correct if the pricing model means to average across that spread. For most pricing models the spread is the point.

Recording each operation—every completion, retrieval, and tool call—gives the data for cost composition and honest pricing. The bill for that detail is volume: far more billing events per customer request, so the ingestion path has to carry the throughput, and the schema has to carry attribution linking each operation back to the request that started it.

Stochasticity: You Cannot Pre-Compute the Bill

Models are not deterministic. The same prompt can come back longer one time than another. An agent deciding whether to reach for a tool will sometimes reach and sometimes not. Branches in the code may or may not fire on a given run. So the exact resource cost of a customer input cannot be known in advance, and the historical average for an input type is an estimate, not a promise.

The meter therefore has to record what happened rather than what was expected. Pre-billing on projected usage is out; the practice is to record actual consumption and reconcile against it. The event is written after the operation finishes, never before or during it, and it carries real tokens consumed (or whatever resource unit applies), not a projection. Metering on predictions across an AI system overcharges some accounts and undercharges others as the model-level variance compounds through a billing period.

Attribution: Who Owns This Model Call?

When several customer workflows run at once over shared model infrastructure, splitting the cost correctly depends on attribution metadata attached at the point of metering. In theory that is simple: every call carries a customer_id and a workflow_id in its billing event. In practice it unravels when AI frameworks invoke models through layers that drop the context.

A pattern that recurs: the top-level workflow manager forwards customer and workflow context correctly to the first-level agent. That agent calls a sub-agent through a framework function, and the function does not pass the context on, because billing was never part of its design. The sub-agent’s model calls land without a customer attached. Come invoice time they are unattributed compute with no defensible way to hand them to the right account.

The fix is explicit propagation. Attribution has to be a first-class parameter that every layer of the agent stack passes along deliberately. Implicit mechanisms such as thread-local storage or a shared global context object break at async boundaries, and every break is an attribution gap.

When Entry-Point Metering Is Enough

Not every AI product needs operation-level metering on the first day. A product charging a flat rate per completed task, where cost variance between tasks is small enough that margin stays predictable, can do fine with metering at the entry point. The case for going deeper is strong under specific conditions: per-task cost swings widely by task type or customer behavior, the pricing model has to reflect that swing, or customers want itemized usage so they can manage their own spend.

Early on, with simple pricing and low variance, starting at the entry point and adding detail as the model demands is a reasonable trade. The architectural decision worth getting right early is extensibility: build the ingestion API and event schema so operation-level events can be added later without forcing a migration of the customer’s integration.

At bottom this is a data design question. You need to capture enough at the moment the work happens to answer billing questions asked weeks afterward, and those questions shift as the product matures, the pricing model changes, and customers grow. Raw events at the right granularity let you answer them. Summary totals collected at the entry point do not, and rebuilding the layer under live production traffic costs more than designing it properly the first time.

Metering architecture, explained

Monthly notes on event design, operation-level attribution, and the billing infrastructure decisions behind AI products. No noise.