Blog
/
Guides

Billing Mediation: What It Is, the 6 Steps, and an Example

Billing mediation turns raw usage events into clean, billable totals. See the 6 steps, how it differs from rating and metering, and a worked AI example.

Sara NelissenSara Nelissen
Written by
Sara Nelissen
Last updated
July 22, 2026
read time
10
minutes
Billing mediation turns raw usage events into clean, billable totals. See the 6 steps, how it differs from rating and metering, and a worked AI example.

Table of contents

A customer's finance lead emails support with a screenshot. Their own logs show 1.8 million tokens last month, but your invoice says 2.3 million.

Nobody's lying. A gateway timeout triggered retries, each retry emitted the same usage event again, and every copy got counted. Billing mediation is the layer that's supposed to catch that before it reaches an invoice (or a very awkward call with that finance lead).

This guide explains what billing mediation is, where it came from, the six steps every mediation layer runs, and what changes when the usage comes from AI models and agents.

What is billing mediation?

Billing mediation is the process of collecting raw usage records, cleaning and standardizing them, and turning them into billable totals that a rating or billing system can price.

It sits between the systems that generate usage and the systems that charge for it. You'll also see it called billing data mediation or usage mediation.

In practice, a billing mediation system:

  • Collects usage events from every source that emits them
  • Checks and cleans them, dropping duplicates and malformed records
  • Ties each event to the right customer, plan, and account
  • Rolls events up into totals and delivers them downstream

Pricing those totals is a separate job called rating. Deciding whether a customer is allowed to keep using the product is another separate job, handled by entitlements. Mediation feeds both.

Where billing mediation comes from: telecom and call detail records

Billing mediation started in telecom, long before anyone metered an API. Every call that passes through a network switch produces a call detail record (CDR), that tells you who called whom, when, for how long, and which equipment handled it.

Switches from different vendors wrote CDRs in different formats. A single call could produce several partial records as it crossed the network, and some records arrived twice or not at all.

Carriers built mediation systems to collect CDRs from every switch, clean them up, stitch related records together, and hand billing a single consistent feed. The rating engine then applied the tariff, and the billing system produced the bill.

The same problem shows up in software today, with different nouns:

Telecom SaaS and AI products
Network switches and gateways App servers, API gateways, LLM gateways, agent runtimes
Call detail records (CDRs) Usage events (API calls, tokens, agent actions, GPU seconds)
Subscriber number Customer, account, team, user, or agent ID
Partial records from one call Several model calls inside one agent run
Tariff applied by the rating engine Price per token, per credit, or per call

Why AI products push mediation harder

The mediation problems AI products hit are the same ones telecom had. There are just far more of them, arriving far faster.

A traditional SaaS product might emit one billable event per login, per seat change, or per API call. An AI product priced on tokens can emit several events for a single request, and an agent working through a task can emit hundreds before anyone looks at a dashboard.

That volume turns edge cases into daily conditions:

  • Retries emit the same event twice after a timeout
  • Late events arrive after the period they belong to has started closing
  • Model changes alter what counts as a billable unit halfway through a month
  • Multiple sources (your app, your gateway, a batch job) report the same usage in different shapes

Agents also burn through usage faster than any human can. So the numbers mediation produces are needed in seconds, by the systems enforcing limits, and the month-end invoice is only one of their consumers.

Our event-based billing guide covers how those events turn into charges.

How billing mediation works: the 6 steps

Billing mediation works by running every usage record through six steps: collection, validation, filtering, enrichment, transformation, and distribution.

Telecom mediation systems have used these names for decades, and they map neatly onto the four functions a modern usage pipeline needs.

Classic step What it does Pipeline function
Collection Pulls records from every source Ingestion
Validation Rejects malformed or incomplete records Normalization and deduplication
Filtering Drops duplicates and non-billable events Normalization and deduplication
Enrichment Adds account, plan, and org context Aggregation and transformation
Transformation Converts units and rolls events into totals Aggregation and transformation
Distribution Sends totals to every system that needs them Downstream sync

1. Collection

Collection gathers raw usage events from wherever they're generated, whether that's application code, API gateways, LLM gateways, agent runtimes, or batch jobs writing to object storage.

At AI volume, collection usually runs through a queue or streaming pipeline. A burst of events from one customer's batch job can outrun a synchronous database write path, and the ingestion endpoint you load-tested against steady traffic is the one that falls over first.

2. Validation

Validation checks that each record has what billing needs, such as a customer identifier, an event name, a timestamp, and a quantity in a known unit. Records that fail go to a quarantine queue where someone can see them.

The dangerous version is a pipeline that drops bad records without logging them. Those events never show up on an invoice, and nobody notices the missing revenue until a reconciliation months later.

3. Filtering

Filtering removes events that shouldn't be billed, like internal test traffic, health checks, free-tier activity, and duplicates.

Duplicates are the big one. Kafka and many other message systems default to at-least-once delivery, which means a retried event can arrive more than once. Deduplication relies on an idempotency key, a stable identifier for each event, so a retry gets recognized as the same event.

The key should be derived from the source data (for example, {customerId}-{eventName}-{requestId}) so every retry reuses it, and the timestamp should come from the original request, not the retry.

4. Enrichment

Enrichment adds the context a raw event doesn't carry. An event from an inference worker might know the API key that made the call but nothing about the customer, plan, team, or department behind it.

Enrichment resolves that key to an account and attaches the dimensions billing and governance need, such as model, region, team, and user.

In telecom, this step also included correlation, which involves stitching several partial records from one call into one. For AI products, the equivalent is grouping every model call inside one agent run.

5. Transformation

Transformation converts events into the units your pricing uses and rolls them up into totals. That might mean summing input and output tokens separately, counting unique active users, taking the peak of concurrent sessions, or converting tokens into credits at a defined rate.

The aggregation window matters more than it looks. If you align it badly, one continuous session gets split across two billing periods (and two slightly confusing invoices).

6. Distribution

Distribution delivers the final totals to every system that depends on them: the rating engine, the billing engine, the entitlements layer, the customer-facing usage dashboard, and the data warehouse.

Each consumer needs its own delivery with retries and dead-letter handling. The support tickets that hurt most are the ones where two of these systems show two different numbers for the same customer.

A billing mediation example: one AI request

Here's what those steps do to a single request. A customer's AI feature makes one model call with 2,400 input tokens and 600 output tokens.

The raw event leaves the inference worker as a log line. It has a service name, a timestamp, an API key ID, and a token count buried in a JSON blob nobody designed for billing:

{
  "svc": "inference-worker-3",
  "ts": "2026-10-28T14:03:11.482Z",
  "key_id": "ak_4471",
  "usage": { "in": 2400, "out": 600 }
}

After mediation, the same event has a stable idempotency key, a resolved customer, a named event type, and typed dimensions every downstream system can read:

{
  "idempotencyKey": "cust_88213-llm.completion-req_5d1e09",
  "customerId": "cust_88213",
  "eventName": "llm.completion",
  "timestamp": "2026-10-28T14:03:11.482Z",
  "dimensions": {
    "model": "chat-large",
    "input_tokens": 2400,
    "output_tokens": 600,
    "team": "support-agents",
    "source": "inference-worker-3"
  }
}

The field names above follow Stigg's raw event schema, although other systems name them differently.

The important part is the structure, including a stable key for deduplication, a resolved customer ID, an explicit timestamp, and quantities the aggregation step can sum without guessing at units.

From there, transformation adds 2,400 to the customer's input-token total and 600 to the output-token total for the period.

If the plan bills in credits at, say, 1 credit per 1,000 input tokens and 4 credits per 1,000 output tokens, this request costs 2.4 + 2.4 = 4.8 credits.

Distribution then sends the new totals to the credit balance, the usage dashboard, and billing.

Event schemas and pipeline design go much deeper than one request. Our usage metering guide covers both in detail.

Billing mediation vs. rating vs. metering

Billing mediation prepares usage data, metering measures it, and rating prices it. Vendors draw the lines between them differently, and some fold metering or rating into "mediation," which is why the terms get muddled.

Layer What it does Output Question it answers
Metering Records that usage happened Raw usage events "What did this customer do?"
Billing mediation Collects, cleans, enriches, and aggregates those events Billable totals per customer and period "What usage counts, and for whom?"
Rating Applies prices, tiers, discounts, and commitments Charges "What does that usage cost?"
Billing Turns charges into invoices and collects payment Invoices and payments "What do we send and collect?"

Billing mediation vs. rating

Rating takes mediation's output and applies per-unit rates, tiers, volume discounts, minimums, and prepaid commitments. It's usually part of the billing engine.

A customer disputing a charge is either disputing the quantity (a mediation problem) or the price applied to it (a rating problem), and the solution lives in a different system for each.

Billing mediation vs. metering

Metering is the instrumentation that emits usage events in the first place. Mediation takes those events, often from several meters at once, and makes them consistent enough to bill. Our metering and billing guide covers how the two layers hand off.

Benefits of billing mediation

A mediation layer has a number of key benefits:

  • Accurate invoices: duplicates, test traffic, and malformed records get filtered before they become charges
  • Less revenue leakage: dropped and unattributed events get caught in validation, which closes one of the most common causes of revenue leakage
  • One number everywhere: billing, entitlements, dashboards, and finance all read the same totals
  • Faster pricing changes: new meters and units get added in one place without touching every downstream system
  • An audit trail: every invoice line can trace back to the events that produced it, which turns a dispute into a query

Mediation and your billing system

Billing systems like Stripe, Zuora, and Chargebee are built to price usage, generate invoices, and collect payment. They expect the usage they receive to be correct already, and mediation is the work that makes it correct.

For high-volume token and agent usage, it looks a lot more like data engineering than accounting, and it sits upstream of whatever billing system you already run. Getting it right gives your billing system numbers it can trust, without changing the billing system itself.

Build vs. buy for the mediation layer

For a product with one usage metric and a single event source, a homegrown mediation pipeline is often the right call. A scheduled job that pulls, cleans, and aggregates usage once a day can hold up for a long time at that size, and there's no reason to replace something that works.

The strain tends to show up under specific conditions:

  • More sources: a second product line or an acquired service starts emitting usage in its own format
  • More volume: event counts climb high enough that daily batches introduce real lag
  • More consumers: billing, entitlements, and dashboards all need the same numbers, and they start drifting apart
  • More enterprise: customers ask for usage broken down by team, department, user, and agent
  • More pricing changes: a pipeline built for today's model breaks when the pricing model changes a few months later

Teams that build this themselves usually underestimate the edge cases and the ongoing maintenance, which pulls engineers away from the product they were hired to build. Your team can almost certainly build it, and it will likely take their next two quarters of product time to do it well.

What to look for in a mediation layer

Whether you build it or buy it, the same checks separate a mediation layer that holds up from one that drifts.

What to look for Why it matters What happens if it's missing
Ingestion built for bursty traffic AI usage arrives in bursts tied to single sessions Peak load drops events at the moments that matter most
Idempotent ingestion Retries and at-least-once delivery are a given at volume Duplicate events get billed as real usage
Visible handling of invalid events Bad records need a fix, and someone has to see them first Unbilled usage disappears with no trace
Enrichment by account and org level Enterprise customers want usage by team, user, and agent Usage can't be split or governed below the account
Configurable aggregation per meter Different pricing models need different aggregation One fixed window works for one product and misbills the next
Retries and dead-letter handling downstream Every consumer has to get every update eventually Two systems show two numbers for the same account
Raw events kept for audit Disputes need a trail from invoice line to source event Every dispute becomes a guessing game

Our billing stack guide shows where mediation sits among the other layers, and our usage-based billing guide covers what sits on top of it.

Make every invoice line trace back to an event

Billing mediation is the layer most usage-based systems underinvest in until a reconciliation problem forces the issue. When it works, the totals behind every invoice, credit balance, and usage limit come from the same clean set of events.

For AI products, those totals also have to arrive fast enough to enforce limits while the usage is still happening. A number that's correct at month-end and stale during the session that burned the budget only does half the job.

Stigg is the usage runtime for AI products. It decides in real time what every customer, user, and agent is allowed to use, and it runs the usage pipeline behind those decisions (ingestion, filtering, and aggregation) alongside the billing system you already use.

With Stigg, engineering teams can:

  • Report raw events with dimensions: send usage through REST, GraphQL, or SDKs for TypeScript, Python, Go, Ruby, C#, and Java, or ingest from Amazon S3 and Google Cloud Pub/Sub
  • Count every event once: each raw event carries a required idempotency key, and an event counts as a duplicate when its key, customer, event name and timestamp all match, so a retry is recognized no matter how late it’s reported
  • Aggregate the way you price: count, count unique, sum, maximum, minimum, and average, calculated over any dimension you report
  • Meter at volume inside your own cloud: BYOC metering runs on Kafka, Flink, and ClickHouse in your VPC, handles 1M+ events per second, and has no per-event cost
  • Keep a raw-event audit trail: on BYOC, a hot path aggregates per customer and feature in 1-minute windows while a cold path stores every raw event, so each aggregate traces back to its source
  • Attribute usage up the org tree: hierarchy enrichment rolls events up through user, team, department, and organization before they hit storage, which is what lets AI usage control split a credit budget by team and agent
  • Enforce limits on the result: AI credits and entitlements use the mediated totals to allow or deny usage before the expensive work runs, with balance checks returning at P99 under 10ms when deployed as a sidecar
  • Keep your billing stack: native integrations for Stripe, Zuora, Chargebee, and Airwallex, so mediation is a layer you add, without replacing billing
  • Meter agent runs end to end: Agent Spend Control meters every agent, sub-agent, and action in a run, and puts budget and usage context inside the run so the agent can adjust or stop before it spends

When the system that cleans your usage data is the same one enforcing limits on it, the numbers your product allows and the numbers your invoice charges stop drifting apart.

If you're working on this layer now, the Stigg docs are a good place to start, or talk to a human about how it would fit into your stack.

FAQs

What are the three types of billing methods?

The three types of billing methods for software are usually subscription billing, usage-based billing, and hybrid billing.

Credit-based billing, where customers prepay for credits or tokens and spend them down, belongs between usage-based and hybrid, and it’s now the default for most AI products.

Mediation matters least for flat subscriptions, produces the totals usage-based billing prices, and feeds both the included allowance and the overage meter in hybrid plans.

Our types of billing guide breaks these into eight models.

What's the difference between billing mediation and metering?

The main difference between billing mediation and metering is scope. Metering records that usage happened, while mediation collects that recorded usage from every source, cleans and deduplicates it, and aggregates it into totals that billing and entitlements can use directly.

Do I need billing mediation if I already have usage-based billing?

Sometimes. You need billing mediation if your usage data comes from more than one source or arrives with duplicates, gaps, or inconsistent formats.

Usage-based billing tools price and invoice usage, but they expect clean inputs, so a single well-structured event source may need very little mediation while several sources usually need a dedicated layer.

How is billing mediation different for AI products?

Billing mediation for AI products differs mainly in volume and velocity. Token and agent usage can produce hundreds of billable events per session, and the totals are needed in seconds to enforce credit balances and usage limits, which raises the bar for ingestion, deduplication, and enrichment.

Can billing mediation prevent revenue leakage?

Yes, billing mediation reduces revenue leakage caused by bad usage data, such as dropped events, duplicates, and usage attributed to the wrong account. However, it doesn't fix leakage from pricing errors, missed renewals, or unenforced limits, which live in rating, contracts, and entitlements.

Where does mediation sit relative to entitlements?

Mediation sits upstream of entitlements. A billing mediation system turns usage that already happened into clean totals, and entitlements use those totals to decide whether the next request is allowed, so the accuracy of every limit check depends on the mediation layer underneath it.

Latest news.

One email per month.
From engineers, for engineers.

Thank you! Your submission has been received.
Oops! Something went wrong while submitting the form.