Topic hub

Usage metering

Counting what your customers used, in a way that still holds up months later when one of them disputes the number. 51 articles on ingestion, dedupe, meter design, rating and storage — grouped in the order the problems actually bite.

Metering is the part that fails silently

An invoicing bug is visible and correctable — you issue a credit note and move on. A metering bug is not: an event that was never counted is gone, because the traffic has passed and there is nothing left to replay. That asymmetry is why metering deserves its own design attention rather than being treated as the easy half of billing.

Everything below is written from systems that are running, including the mistakes. Where a section describes a bug, it is usually one this codebase has had.

Start here

What a metering system has to guarantee before anything downstream of it can be trusted, and the shape of the API that provides it.

Usage Metering API: How to Build Billing-Grade Event Metering

A metering API has one job a normal API does not: every event it accepts must still be countable, exactly once, months later, in front of a customer disputing the number. Idempotency windows and scope, event identity versus request identity, late and out-of-order events, aggregation changes mid-period, price versioning, and explainability.

September 5, 2026 · 10 min read

What a Billing API Must Actually Do (Five Requirements, In the Order They Bite)

Most billing API evaluations start at the invoice endpoint, which is the end nobody fails at. Projects fail at ingestion: idempotency, late and out-of-order events, live balances, price changes that must not restate closed periods, and proving how a number was derived. The five questions to ask, and the bad answers to listen for.

August 26, 2026 · 9 min read

Why Usage Metering Needs Its Own Database (and What a SQL Table Quietly Breaks)

Most usage-pricing writing is about reading the meter your vendor gives you. This is about the layer underneath: the database that records usage and turns it into an invoice line. The default choice - a plain SQL usage_events table - breaks on the four invariants billing actually requires: idempotency (retries double-count without a stable event_id), immutability (mutable rows destroy the audit trail behind every charge), cheap account-month totals (SUM over millions of rows under a lock does not scale), and correctness under late data (a corrected event after you have invoiced silently changes a number you already billed). What a purpose-built metering store does instead: dedupe on ingest, append-only immutable segments, rollups as the fast path with raw as the truth and a raw-vs-rollup verify, and period close with a frozen snapshot plus pending adjustments. Why this is a real database problem - the same one driving the 2026 metering acquisition wave - and how UsageBox gives you idempotent, auditable, reconcilable invoices without the build.

June 15, 2026 · 9 min read

Getting events in

Ingestion is where billing projects actually fail. Retries, late arrivals, at-least-once collectors, and the counting that has to stay correct through all of it.

Inside usageDb's Ingest Path: WAL, Memtable, and the Durability Contract

How usageDb turns an acknowledged usage event into a durable, billable fact: the three-phase ingest critical section, the fsynced write-ahead log, Strict vs Fast durability modes, and the memtable re-insert rule that keeps a failed flush from silently stranding data.

June 4, 2026 · 9 min read

Designing meters

A meter is a value type, a unit and an aggregation. Those three choices decide what your invoice can say, and two of them are painful to change afterwards.

Things that are hard to count

Every product has usage that resists a simple counter — cached reads, sub-agents, crawlers, resold capacity, other people’s customers.

Prompt Caching Is Quietly Breaking Your AI Cost Tracking (Cache Reads vs Writes, and the Numbers That Lie)

Prompt caching is the best per-call cost lever in 2026 - up to 90% off repeated context, stackable with batch discounts to ~25% of standard rates - but it quietly breaks cost tracking. A cached request still reports the full input-token count, so any tracker that multiplies total input tokens by the standard rate overstates spend on cache-heavy workloads (up to ~10x) and hides whether caching is working at all. The bug is real and current: the LiteLLM team logged "Anthropic cost tracking inaccurate for cached usage" (LIT-3771) in its June stability sprint, with an enterprise customer confirming it in production. The fix is an accounting rule, not a discount: meter cache writes, cache reads, and uncached input as three separately-priced events, and your dashboard goes from lying to load-bearing - surfacing both true cost and cache hit ratio.

June 18, 2026 · 6 min read

Who Spent the Tokens? Cost Attribution Across Tools, Sub-Agents, and Retries (2026)

A single agent run fans out into tool calls, sub-agents, parallel branches, and silent retries, then returns one opaque token total - and the expensive question (which customer, feature, step, and model burned the spend) cannot be reconstructed from it after the fact. Attribution is a write-time property: every model call has to be tagged with a few dimensions (trace id, customer, feature, step, model) and emitted as a usage event the meter rolls up by any of them. This explains why provider exports and application logs cannot attribute agent cost, the exact dimension set that makes a token traceable, and the idempotency rule (count each event id once) that stops retries and at-least-once collectors from double-counting an agent's own spend. For AI products, attribution is not a report - it is the billing system.

June 22, 2026 · 8 min read

Should You Bill for Bot and Crawler Traffic? Keeping Non-Human Usage Out of Metered Invoices

When you bill per request, per API call, or per GB, AI crawlers and scrapers can inflate a customer's usage and your own infrastructure bill. One developer was charged for 11 million Meta crawler requests in 15 days, and robots.txt will not save you because it is advisory. How to detect bot traffic, define what counts as billable, and exclude non-human events at the meter before they reach an invoice.

June 4, 2026 · 9 min read

Selling an API on RapidAPI: Metering Your Subscribers Beyond the Marketplace Quota

RapidAPI enforces plan quotas at its gateway, but providers who need per-subscriber usage, cost-shaped dimensions, or marketplace and direct-channel parity need their own meter behind it. The proxy-secret trust model, subscriber auto-provisioning, the plan-sync webhook, and reconciliation that ends arguments.

August 22, 2026 · 9 min read

From quantity to money

Metering produces quantities. Rating turns them into amounts, and the step between the two is where pricing decisions become reversible or permanent.

AI API Billing in 2026: Tokens, Credits, Requests or Outcomes?

The unit you measure and the unit you bill are not the same unit, and collapsing them is what makes AI pricing impossible to change later. What each of the four units really costs to implement, where each one breaks, what outcome pricing actually requires, and the architecture that lets you switch between them without re-instrumenting your product.

September 5, 2026 · 11 min read

UsageBox Kata #1: From Token Event to Invoice Line in 30 Minutes

A hands-on kata: take a raw AI usage event - a chunk of Claude tokens, a tool call, a credit burn - and turn it into a stable, auditable invoice line using UsageBox, in about 30 minutes, without building a billing database. Six steps against the real metering API: send your first usage event; make retries safe (idempotent dedupe by event_id, with same-id-different-payload surfaced as a conflict); read a cheap month-to-date total from rollups; pull the immutable audit trail behind a disputed line with /explain; close the period to freeze the invoice while corrections land as net adjustments; and run a raw-vs-rollup /verify so the fast number always equals the true number. Plus production notes, kata variations (per-model cost, live spend caps, vendor-bill reconciliation, ad-hoc SQL), and what you just avoided building.

June 16, 2026 · 7 min read

Storage and correctness

Why usage data resists a normal database, and what a purpose-built one does differently — written up from the engine underneath UsageBox.

usageDb's Columnar Segment Format: Encodings That Shrink Usage Data

How usageDb's custom .seg columnar format uses dictionary, delta, zigzag-varint, run-length, and plain encodings plus per-column zstd and a blake3 checksum to turn huge but repetitive AI usage data into tiny, cheap-to-scan immutable billing audit segments.

June 4, 2026 · 9 min read

Compaction in usageDb: Merging Segments Behind an Atomic Manifest Swap

How usageDb background compaction merges many small per-bucket segments into one well-sorted, well-compressed output, swaps it in through an atomic manifest commit, and defers deletion of the old immutable files behind a reader grace period so no in-flight query ever fails.

June 4, 2026 · 8 min read

Proving usageDb Correct: Property Tests and Deterministic Simulation Testing

How usageDb, the open-source Rust usage database behind UsageBox, verifies its billing invariants: proptest property tests over thousands of random inputs, plus deterministic simulation testing that runs random crash, restart, and manifest-corruption sequences against a parallel reference model.

June 4, 2026 · 10 min read

Choosing a platform

Stripe took Metronome, Adyen took Orb, Salesforce took m3ter and Kong took OpenMeter. The buying question changed from which product is best to whose ecosystem you are joining.

Best Usage-Based Billing Platforms for AI in 2026: 9 Compared

Stripe took Metronome, Adyen took Orb, Salesforce took m3ter. A side-by-side of Stripe Billing, Metronome, Orb, Lago, Flexprice, OpenMeter, Amberflo, Chargebee and UsageBox — what each one meters, where each one stops, and the five questions to ask before you commit to an ecosystem.

September 5, 2026 · 11 min read

Metronome Alternatives in 2026: 7 Options After the Stripe Acquisition

Metronome is a Stripe product as of January 2026. If you chose it for a metering engine that was independent of any payment processor, that is the part that changed. Orb, Lago, Flexprice, OpenMeter, Amberflo, Chargebee and splitting the meter from the biller — what each is good at, when not to move at all, and a migration checklist.

September 5, 2026 · 9 min read

Lago Alternatives in 2026: Open-Source Usage Billing Compared

Lago is one of the few usage-billing platforms an acquisition cannot take away from you, and for many teams the right answer is to stay. Two things comparisons miss: the free self-hosted stack is not the one behind its throughput numbers, and AGPLv3 has real terms. Flexprice, OpenMeter, Amberflo, Chargebee, Orb and Metronome, matched to the complaint you actually have.

September 5, 2026 · 9 min read

Orb Alternatives in 2026: After the $335M Adyen Acquisition

Adyen closed its acquisition of Orb on 1 July 2026 and runs it under an incubator model, so nothing breaks today. The sentence to read carefully is that multi-PSP support "continues initially". Metronome, Lago, Flexprice, OpenMeter, Amberflo and Chargebee compared, plus how to tell whether you actually need to move.

September 5, 2026 · 9 min read

OpenMeter Alternatives in 2026: What the Kong Acquisition Changed

OpenMeter is Kong's, but it is Apache 2.0 — so unlike the other 2026 acquisitions, nothing can be taken back from a version you already have. What changed is the centre of gravity: it is becoming Konnect Metering & Billing. Lago, Flexprice, Amberflo, Metronome and Orb compared, and why the real question is whether you run Kong.

September 5, 2026 · 8 min read

Flexprice Alternatives in 2026: Credit-Based Billing Compared

Flexprice is the credits-native option — AGPL-3.0, self-hostable, publicly priced, on a Postgres–Kafka–ClickHouse–Temporal stack. Lago, OpenMeter, Amberflo, Metronome, Orb and Chargebee compared against it, plus the five things that make building a credit ledger yourself harder than it looks.

September 5, 2026 · 9 min read

Stripe Billing Alternatives for Usage-Based Billing in 2026

Most teams looking for a Stripe Billing alternative have a metering problem, not a Stripe problem — and Stripe's own answer to it is now Metronome, which is also Stripe. How to tell the three complaints apart, when putting a metering layer in front of Stripe beats replacing it, and the real options if you are leaving the payment rail too.

September 5, 2026 · 8 min read

The Usage-Based Billing Vendor Landscape After the 2026 Consolidation

Stripe took Metronome, Adyen took Orb, Salesforce took m3ter, Kong took OpenMeter. Four acquisitions changed the buying question from which product is best to whose ecosystem you are joining — and why they all bought rather than built says something useful about how hard metering actually is. What to ask a vendor now, and why keeping raw events exportable is the cheap insurance.

August 26, 2026 · 7 min read

When it goes wrong

Disputes, drift, retry storms and bill shock. The failure modes are predictable, which means most of them are preventable at design time.

Retry Storms: How One Bad Hour Rebills More LLM Tokens Than a Month of Servers (2026)

Why did one day of AI cost more than a month of servers? A retry storm. When a model call times out or 5xx's, retry logic fires again, and each attempt that reaches the provider is a fresh, fully-billed generation - even the ones your app throws away. A slow provider hour plus aggressive retries plus concurrency multiplies spend by the retry count, with no fixed ceiling the way a server bill has. The five controls that cap it (hard retry limit, exponential backoff with full jitter, circuit breaker, retry only retry-safe statuses, idempotency keys), why 429s are a trap, and why the meter has to count attempts - not just successes - so the storm shows up the same day instead of on the invoice.

July 24, 2026 · 7 min read

Metered AI Billing Is Breaking Developer Trust. That Is an Engineering Failure, Not a Pricing One

The June 2026 revolt against metered AI billing (the GitHub Copilot credit switch, "pay the same, get anxiety for free", Cursor forced usage pricing) is real, but the diagnosis is wrong. Usage-based pricing is not the betrayal. Shipping usage-based pricing without real-time metering, pre-flight cost, and enforcing caps is. The four engineering properties trust actually requires.

June 6, 2026 · 9 min read

UsageBox Kata #3: Reconcile a Vendor Bill Against Your Meter

Close the gap between what a model vendor like Anthropic or OpenAI bills you and what you metered and charged customers. A hands-on kata: pull your per-model total, verify your own rollups against a raw scan before you blame anyone, lay your number next to the vendor invoice, localize the gap with /explain and dimensions, separate a metering gap from unbilled pass-through overhead (retries, cached reads, system-prompt tokens), and close the loop with Correction events so the audit trail proves the reconciliation. Production notes, variations (daily reconciliation, per-customer margin), and FAQ.

June 16, 2026 · 8 min read

Metering you can point at any biller

UsageBox is the metering layer, not a billing suite: idempotent ingest with a documented dedupe window, a stated late-event policy, per-account key scoping, and raw events you can export.