← manishpande.in Contents
Reference architecture · 2026 The Agentic Platform by Manish Pande
© 2026 Manish Pande Mumbai, India Set in Space Grotesk · Source Serif 4 · JetBrains Mono
OPS · Metering & Billing Chapter 25

The Metering & Billing Surface: From Usage Event to Invoice

Chapter 20 made cost a runtime constraint and showed where the spend comes from. Turning "the gateway processed 1.3 million tokens" into "this customer owes $X, and we earned $Y of margin on it" is a different system with different requirements. Telemetry can drop a span and no one is harmed; a billing pipeline that double-counts or loses events either erodes customer trust or quietly erodes margin. The discipline is to separate the high-volume, real-time metering path from the low-volume, financial-grade invoicing path — and to know exactly where the seams are so you can decide what to build and what to buy.

25.1 The decomposition

Usage becomes money through a chain that most tools blur together; naming the stages tells you where your platform ends and a billing vendor begins. Meter — count what happened. Mediate — deduplicate and normalize the raw events. Rate — apply pricing to produce charges. Bill — aggregate charges over a period. Invoice — render the bill. Collect — take payment. Recognize — book the revenue. The first three are high-volume and real-time; the last four are financial and audited. The boundary between them is the most important architectural line in the whole surface.

Model Gatewaymeter point Ingestidempotent Aggregatewindows · balance Ratepricing Invoice Payments usage sourcessandbox · tools · storage provider invoicesreconcile margin balance → throttle / block · Ch.19
Fig 25.1 · The metering-to-revenue pipeline. The gateway is the canonical meter point; other usage (sandbox-seconds, tool calls, storage) joins at ingest, which deduplicates on idempotency keys. Aggregate maintains real-time balances; rate applies pricing, reconciled against provider invoices to protect margin; then invoice and payments close the financial end. The dashed loop is the enforcement half of Chapter 20: the live balance feeds back to the gateway to throttle or block an over-budget tenant.

25.2 The emission surface — where usage is born

The model gateway is the canonical meter point. It already sees the model, the input/output/cached token split, latency, and success or failure (Ch. 6, Ch. 18), so metering rides on instrumentation you built anyway. Other dimensions join from their own sources: sandbox-seconds (Ch. 9, Ch. 24), tool calls (Ch. 8), retrieval and storage (Ch. 1011), and seats. Every usage event carries an idempotency key — naturally run_id plus step_id — so that at-least-once delivery deduplicates to effectively-once. And you reconcile metered tokens against the bills you receive from Bedrock, Anthropic, or OpenAI: the gap between what you metered and what you were charged is your margin alarm.

25.3 The stack and the integration strategy

Table 25.1 — Metering and billing platforms (representative)
ToolShapeNotable for
LagoOpen-source metering + billingEvent ingestion, aggregation, plans, invoicing, prepaid wallets/credits
OpenMeterOpen-source, CloudEvents-basedReal-time aggregation oriented to AI token metering; Stripe integration
MetronomeUsage-based billing platformReal-time, high-scale; used by large AI vendors
OrbEvent-based usage billingFlexible usage models and revenue reporting
m3terMetering & rating engineComplex rating feeding an existing billing system
Stripe BillingBilling + paymentsMeter events, usage pricing, invoicing, and collection in one

The strategy that holds these together: ingest events idempotently and tolerate late or out-of-order arrival; pre-aggregate so a real-time balance is always queryable; choose prepaid wallets with real-time decrement or postpaid metered invoicing per product; and price across multiple dimensions — per-token (input, output, and cached differ), per-run, per-tool-call, per-seat, a platform fee, a markup on raw model cost. The defining move for an agentic platform is to close the loop: the aggregated balance feeds back into the gateway so an over-budget tenant or runaway agent is throttled or blocked in real time. Metering and the budget enforcement of Chapter 20 are two ends of one mechanism.

First principle · Meter at the gateway, enforce at the gateway, invoice downstream

One source of truth for usage — the gateway — feeds both the real-time control loop that caps spend and the financial pipeline that bills it. Keep the high-volume metering path separate from the audited invoicing path, but let both read from the same metered events, so what you enforce and what you charge can never disagree.

Hazard · Metering drift, double-counting, and sensitive usage data

Retries, fan-out, and multi-agent calls (Ch. 12) make it easy to emit the same usage twice; without idempotent keys and provider reconciliation you over-bill (and lose trust) or under-bill (and lose margin). And usage events are commercially sensitive and often carry tenant identifiers — they fall under the same residency and PII rules as traces (Ch. 17, Ch. 18), not a laxer standard because they're "just counters."

· · ·