New guide

Refine your pricing strategy with a complete guide to pricing economics for AI agents.

Get the guide
×

Engineering problems behind AI billing

Why subscription billing platforms leave a gap in AI products, and why filling it with a usage table and a background job fails under real traffic.

Engineering problems behind AI billing

Sooner or later, every AI company hands its engineering team the same assignment: make billing work. Usually that arrives after pricing has changed twice, the margin spreadsheet has become a weekly ritual, and someone has asked why the existing billing tool cannot just handle it.

This is the first of three pieces written for the engineers who get that assignment:

  1. Problems in AI billing (this piece): why off-the-shelf billing platforms do not cover what AI products need, and why simple application logic cannot close the gap.
  2. Implementation guide (coming next): the requirements, data model, architecture, and patterns needed to build it properly.
  3. The true cost of building AI billing in-house: what that system costs in people and infrastructure over three years.

Established billing platforms were designed for a different kind of business, so AI companies end up building a layer of their own. That layer is infrastructure, with all the reliability requirements the word implies, and it cannot be bolted onto the application.

Part 1: Why existing billing platforms fall short

Stripe Billing, Chargebee, Zuora, and Recurly are excellent products. Over roughly 15 years they have become good at the problems subscription software has: a catalog of plans, a quantity of seats, a renewal date, prorations, dunning, tax, invoices, and payment collection. If a company sells a fixed plan at a price that holds for a year, they work.

Their core data model reflects that world. A customer has a subscription; a subscription has plan items; each item has a price and a quantity; at the end of the period, the system produces an invoice. Usage-based billing has been added on top, and the leading platforms have invested heavily in it. Stripe, for example, has extended its billing product for usage-based and hybrid models and, after acquiring the metering platform Metronome, says it is extending support to multidimensional metering for complex AI product catalogs.

The shape of the problem in an AI product is different, and five gaps keep appearing when engineering teams try to map their product onto these platforms.

Gap 1: They expect one billable event; an AI product emits many

A billing platform expects to receive a billable quantity: 3 seats, 12,000 API calls, 40 GB. The meter counts it, multiplies it by a price, and puts it on an invoice.

An AI product produces raw activity. A single customer request to a support agent can fan out into several model calls on different models, a retrieval step, two tool calls, and a text-to-speech response. Each has its own token counts and its own provider cost. The customer, meanwhile, is buying something else entirely: one resolved ticket, one processed document, or a number of credits.

Turning that activity into a billable unit is composition logic: group events by run, weight tokens differently per model, apply per-customer conversion rates, decide whether the outcome succeeded, and round once per unit instead of once per event. Billing platforms aggregate events that are already defined, and the rules for what a unit is live somewhere else. So that logic lands in the company's own code, upstream of the billing platform, and the billing rules now live in two systems that have to be reconciled in a third.

Gap 2: They record what was invoiced, and nothing about what it cost

A billing platform knows what each customer was charged. It was never designed to know what serving that customer cost, because in subscription software that cost was small and stable enough to ignore.

In AI, cost is large and it moves. Take two customers on the same $1,000 monthly plan. One sends short prompts to a small model and costs $180 in provider fees. The other runs long contexts, many retries, and a larger model, and costs $700. On the revenue chart and in the billing tool they are identical. The difference shows up in the P&L a quarter later, after sales has signed more contracts that look like the expensive one.

For engineering, this means cost has to be captured at the same moment as usage: every event needs the provider, model, and token counts, priced against a versioned cost catalog, and joined to the revenue it produced. Some platforms have started to add tools for tracking inference costs, but margin per customer, per agent, per model, and per run is rarely a first-class part of the billing data model. Teams that need it build it themselves.

Gap 3: Prepaid balances are treated as accounting

AI contracts routinely combine a platform fee, a prepaid wallet the customer tops up, and pay-as-you-go usage once the wallet runs dry. Some customers hold several balances at once: standard credits, premium credits for reasoning models, and promotional credits that expire.

In most billing platforms, prepaid value is an accounting construct: a credit balance applied against an invoice at the end of the period. An AI product needs something else. Before it starts an expensive agent run, it has to ask, in milliseconds, whether this customer can afford it, and then debit the right balance in the right order as the run consumes resources. That is a real-time, concurrency-safe operation on the hot path of the product, running long before any month-end reconciliation.

So the live wallet ends up in the application, the subscription stays in the billing platform, and the two disagree at the end of every billing cycle.

Gap 4: Pricing is assumed to change yearly; AI pricing changes monthly

Subscription billing assumes pricing is a periodic decision: set the catalog, sell against it, revisit next year.

AI pricing moves far more often. Provider prices drop, new models launch, a competitor reprices, the first unit of value turns out to be wrong. Enterprise deals add their own layer: a discounted rate on one model, a different credit conversion, a committed spend with a cap, a minimum margin for one strategic account.

Each of those changes touches the composition logic from Gap 1, the cost data from Gap 2, and the wallet rules from Gap 3, none of which live in the billing platform. So each change becomes catalog work in one system, code changes in another, and migration logic for existing customers in both. Nobody planned to staff a billing team. The product engineers become one anyway.

Gap 5: The independent metering layer is being absorbed

The usual answer to Gaps 1 to 4 was to add a dedicated usage-billing vendor in front of the billing platform. In 2026 that option narrowed sharply. Stripe completed its acquisition of Metronome in January. In June, Adyen agreed to acquire Orb for $335 million, days after Salesforce agreed to acquire m3ter.

These products continue to operate, and the acquirers have said they will keep supporting existing customers. Even so, the layer that decides what a company charges now sits inside companies that also process its payments or own its CRM. For teams that want pricing logic independent of their payment processor, the number of independent choices has shrunk.

The result: a missing middle layer

Taken together, the five gaps describe a layer that sits between the AI product and the billing platform. The billing platform still does what it is good at: invoices, tax, and collecting payment. Everything before that, turning raw activity into the commercial unit the company sells and connecting it back to cost, has nowhere to live.

Diagram of the missing layer between an AI product and its billing platform: the AI product emits model calls, tool calls, retrieval steps, and agent runs; the billing platform handles invoices, tax, payment collection, and dunning; the layer between them composes billable units, prices provider cost, runs live wallets, holds versioned rate cards, and tracks margin per customer.

Every AI company ends up building this layer, whether it plans to or not. What matters is how.

Part 2: Why this cannot be simple application logic

Once a team accepts that the middle layer has to be built, the natural first instinct is to build it inside the existing application. It looks like a small feature:

  1. After each model or tool call, the request handler writes a usage row to the application database.
  2. A cron job or background worker reads unprocessed rows into memory, applies the pricing rules, and updates customer balances.
  3. The results are written to another table, or another database, for reporting and for the billing platform.

It ships in a sprint. It works in the demo, and for the first handful of customers. The problems arrive with real traffic, and they come from the design itself.

Problem 1: Lost events are lost revenue, and nobody notices

The usage write shares fate with the request. If the handler crashes, times out, or rolls back its transaction after the model call has already returned, the provider has charged the company and the usage row was never written. The customer got the answer; the company will never bill for it.

The failure is also silent. A missing row looks exactly like a customer who did not use the product, and no alert fires on data that does not exist.

Problem 2: Retries create duplicates, and duplicates create disputes

The obvious fix for lost writes is to retry them. Retries introduce the opposite failure: the same call recorded twice, the customer billed twice. Preventing that requires idempotency keys generated by the producer, deduplication at every stage, and storage that can recognize a replayed event. None of this exists in a simple usage table.

Problem 3: The background job is a hand-built message queue

The worker in step 2 has to remember which rows it has processed, resume from the right place after a crash, avoid processing the same row twice when two instances run, and move a malformed row aside so it does not block everything behind it. Those are the core features of a message queue: offsets, consumer coordination, and dead-letter handling. Rebuilding them on top of a database table is slow, fragile, and hard to reason about.

Problem 4: Billing work slows the product down

If the request handler also checks balances, applies pricing, and writes analytics, every billing slowdown becomes a slow customer request, and every billing failure becomes a failed one. Even when processing moves to a background job, it shares the same database and connection pool as the product. A spike in usage, which in AI is exactly when billing matters most, is also when the product and billing compete hardest for the same resources.

Problem 5: AI event volume overwhelms a transactional database

AI usage is machine-paced. One user action can trigger an agent loop with a dozen billable events, and a single enterprise batch job can produce millions in an hour. Every one is an insert and an index update on a table that only grows, followed by aggregation queries over the same table. Transactional databases are built for many small reads and writes. Continuous high-volume ingestion plus analytical scans is a different workload, and the product's own queries suffer first.

Problem 6: Every deploy is a billing outage

Because capture and processing live in the application, every release, restart, or scale-down interrupts them. In-flight work held in memory is lost; half-processed batches are left in an unknown state. The billing pipeline inherits the deploy cadence of the product, which in an AI company can be several times a day.

Problem 7: Analytics on raw rows does not scale

Revenue teams want spend, revenue, cost, and margin per customer, agent, and model, close to real time. Computing those numbers by scanning millions of raw usage rows on every dashboard load is slow and expensive, and running those scans on the production database makes Problem 4 worse. The numbers need to be aggregated incrementally as events are processed, in a store designed for it.

What the problem actually requires

Each problem above maps to a specific requirement:

ProblemWhat it requires
Many raw events, one billable unitComposition and rating logic owned outside the billing platform
No view of cost or marginProvider cost captured per event, priced from a versioned catalog
Wallets needed in real timeAtomic, low-latency balance checks and debits, backed by a durable ledger
Pricing changes monthlyRate cards and conversion rules stored as versioned data
Lost eventsDurable capture that survives application failures
Duplicate eventsIdempotency and deduplication at every stage
Hand-built queueA real event stream with checkpoints and dead-letter handling
Billing slowing the productAsynchronous processing, decoupled from the request path
High event volumeHorizontally scalable ingestion and a store built for bulk writes
Deploys interrupting billingAn independently deployed service with graceful shutdown
Slow analyticsAggregates maintained incrementally as events land

Together, these describe a dedicated, highly available microservice with its own streams, cache, ledger, and analytics store, sitting between the AI product and the billing platform.

The implementation guide, coming next in this series, walks through how to build that service, from requirements and data model to architecture and correctness patterns. The cost analysis puts a number on building and running it.

For a quick diagnostic of where your team stands today, open the spreadsheet that sits next to the billing tool, the one where someone reconciles provider invoices against customer invoices every month. Whatever is in that spreadsheet is the list of things the current system was supposed to do and cannot.

Billing engineering, Usage metering, Build vs buy

Vijayanand Kailash

Vijayanand Kailash

Co-founder & CEO, Clocknext

16 years in tech and counting. In-house billing expert and jack-of-all-trades across product and GTM.