When you meter a REST API, each call is a discrete event with a deterministic cost. The call either happens or it does not. If you need to know what a customer consumed, you count the calls. AI infrastructure breaks this property in three ways at once: the same input can produce different resource consumption on different runs, the work a customer initiates is distributed across chains of model calls and tool invocations that they never see directly, and the cost per operation varies by several orders of magnitude depending on model selection and context window size. Standard metering approaches were not built for any of these properties, let alone all three simultaneously.

The Granularity Problem

For a traditional API, the natural metering granularity is the API call. For an AI product, the API call is only the entry point. Behind it is a tree of model completions, retrieval operations, function calls, and sub-agent invocations. The customer initiates one request. The product performs dozens to hundreds of operations to fulfill it.

If you meter only at the entry point, you lose visibility into what drove the cost. Two customer requests may look identical from the outside and consume radically different compute: one resolves in three model calls with short contexts, the other branches into six sub-agents with long context windows at each step. Billing them the same amount is accurate only if your pricing model intentionally averages across that variation. For most pricing models, the variation matters.

Metering at the operation level (each model call, each retrieval, each tool invocation) gives you the data to understand cost composition and to price accurately. The challenge is that this level of granularity generates many more billing events per customer request, which means your metering infrastructure needs to handle the throughput, and your billing schema needs to support the attribution that ties individual operations back to the customer request that initiated them.

The Stochasticity Problem

AI models are non-deterministic. The same prompt may produce an output of different length on different runs. An agent that uses a model to decide whether to call a tool will sometimes call it and sometimes not, based on model output. Workflow branches that exist in the code may or may not execute on a given run. This means you cannot predict the exact resource consumption for a given customer input in advance, and it means historical averages per input type are estimates, not guarantees.

For metering, this requires tracking actual consumption per operation rather than estimating from input parameters. You cannot pre-bill based on expected usage; you must record actual usage and reconcile. The billing event must be emitted after the operation completes, not before or during, and it must record the actual tokens consumed (or other resource units), not a prediction. Prediction-based metering in AI systems will systematically over-charge some customers and under-charge others as model output variance accumulates across billing periods.

The Attribution Problem

When multiple customer workflows run concurrently and they share underlying model infrastructure, attributing the cost of each model call to the correct customer and workflow requires explicit attribution metadata at the point of metering. This is straightforward in principle: every model call should carry a customer_id and a workflow_id in the billing event. In practice, attribution breaks down when AI frameworks call models through abstractions that strip or ignore the attribution context.

A common failure pattern: the top-level workflow manager passes customer and workflow context correctly to the first-level agent. That agent uses a framework function to call a sub-agent, and the framework function does not forward the attribution context because it was not designed with billing in mind. The sub-agent's model calls are recorded without customer attribution. At billing time, those calls appear as unattributed compute consumption with no way to assign them to the correct customer.

The solution is explicit: attribution context must be a first-class parameter that every level of the agent stack forwards explicitly. Relying on implicit context propagation (thread-local storage, global context objects) across asynchronous agent chains produces attribution gaps whenever the context boundaries are crossed.

Where Simpler Approaches Are Sufficient

We are not arguing that every AI product needs operation-level metering from day one. If your pricing model charges a flat rate per completed task and your cost variance across tasks is low enough that the margin is predictable, entry-point metering may be entirely adequate. The business case for operation-level metering is strongest when: your per-task cost varies significantly by task type or customer behavior, your pricing model needs to reflect that variation, or your customers need detailed usage breakdowns to understand and control their own spend.

For products at an early stage with simple pricing and low task cost variance, starting with entry-point metering and adding granularity as the pricing model requires it is a pragmatic choice. The architecture decision that matters most early on is making the metering layer extensible: building the event ingestion API and schema in a way that allows you to add operation-level events later, without requiring a migration of the customer-facing integration.

The metering problem in AI infrastructure is fundamentally a data design problem: you need to capture enough information at the time the work happens to answer the billing questions that will be asked weeks later. The questions change as products mature, pricing models evolve, and customers grow. Metering infrastructure that captures the raw events at the right granularity gives you the data to answer those questions. Metering infrastructure that captures only summary statistics at the entry point does not, and rebuilding it under production load is more expensive than designing it correctly from the beginning.

Metering architecture for AI products

Monthly posts covering event schema design, operation-level attribution, and billing infrastructure decisions for teams building on AI. No noise.