Skip to content
FluxMeter
中文

Writing

Multi-tenant AI usage: tokens by customer, not API key

Multi-tenant AI pools customers on one API key. Customer tokens need attributed usage lines, not key totals. Not a billing suite; no zero-overspend promise.

2026-11-17 · Metering · 8 min read

Your multi-tenant AI product shares a handful of upstream API keys. Tenants behind the gateway, workspaces, resale buyers—their traffic all leaves through those keys. The provider console and your internal boards roll up by key or project. The curves are clear; limits are easy to set. Then someone asks how many tokens this customer used this month, and that same key report barely helps. It was never sliced by customer.

The gap is usually not “do we have enough monitoring?” It is metering granularity. An API-key or project total answers how much this key carried. A multi-tenant product needs how much each customer used. Those are not the same table.

Why your upstream invoice isn’t customer-level usage covered the procurement side: a pooled provider invoice is not customer usage. This piece is the day-to-day view inside your own product: the pool you see by key is still not tokens seen by customer.

API-key / project totals vs customer attribution

The contrast is about grain, not about which view is “more complete.”

API-key / project totals. A key is an upstream credential: authentication, rate limits, and often the provider bill follow the key or project. That is useful operations data—which key hit a limit, which project’s upstream spend is climbing. In a multi-tenant product, many tenants usually sit behind one key. That is how you talk to the provider. It is not the unit you use to allocate cost to customers.

Customer attribution. Your commercial unit is the customer, tenant, or workspace. Support explaining usage, finance allocating cost, product watching which tenant is growing—all ask in that unit. What you need is a usage line attached to that customer: model, tokens, window, and your rate card or cost map. A ratio carved out of a key total is not the same thing.

A common shortcut is to issue one upstream key per customer and let the console treat “key” as “customer.” That can hold when you have few tenants. As the customer count grows, rotation, limits, and permissions become another operations problem. Metering still stops at the provider console’s grain: rates, discounts, and credits are your contract with the provider, and they do not automatically equal what you charge a customer. You still need your own customer-level usage lines.

The missing layer: the usage event must carry the customer when it happens

A key total cannot be reliably “split back” into customers after the fact. The traffic is already mixed on the same credential. Without a customer or tenant id traveling with the event, you are left with ratios or log archaeology—until a dispute arrives.

You need an explicit metering fact layer:

usage event → attributed / priced customer usage line

Event: an observable usage occurrence (tokens, model, timestamp) that already carries your customer or tenant id when it happens.

Attribute: attach it to the right customer (and product or env as needed).

Price (your rules): apply your rate card or cost map; do not paste upstream key or project invoice rows as customer truth.

Line: a queryable, aggregable, exportable customer usage line—the input to allocation or a billing system, not the invoice itself.

With that layer, key and project reports keep serving upstream operations and procurement reconciliation. The customer side speaks from your usage lines. Cross-check them if you want (model totals should roughly rhyme); do not conflate them. One is the credential and the pool; the other is attributed fact.

If the gateway times out or a usage receipt never arrives, you may not know whether an event happened at all. That receipt problem is in the Architecture post on gateway timeouts. This piece covers the quieter failure: even when events arrive, a key total is still not a customer-level usage ledger if the customer id is missing. Traces in an observability stack do not answer it either; see Metering is not observability.

What this layer solves—and what it does not

It fixes metering and attribution grain in a multi-tenant product. It does not issue invoices.

It helps youIt does not replace
See tokens and cost by customer, instead of lumping them under an API keyFull subscriptions, invoicing, collections, tax
Turn gateway / multi-tenant traffic into attributed usage linesStripe, Lago, Orb, Metronome, OpenMeter, or any billing suite
Feed allocation, usage statements, and exportA promise of zero overspend
Keep key / project totals and customer detail comparable but separateTreating HTTP 202 / custody as settlement; ClickHouse as billing truth; Flink as a billing engine

In one sentence: metering stops at the attributed usage line (optionally exported). Invoicing and payment stay in your billing stack. Customer-level visibility is the prerequisite. If you later add a pre-request budget check or prepaid admission, that is an optional control on top of this layer: it can reduce overspend risk, and it does not guarantee zero overspend—see the bound in check / reserve. Customer-level token cost when an agent runs away rests on the same prerequisite: see by customer first, then talk about control.

Where FluxMeter fits

FluxMeter’s positioning is deliberate: Open-source usage metering for AI gateways and multi-tenant products — customer-level tokens and cost, without a full billing suite.

From flux to ledger: ingest usage from a gateway or SDK, move it through custody and stream processing into a queryable ledger, and read attributed, optionally priced customer usage lines from the Usage API. In a multi-tenant product, the first value is seeing tokens and cost by customer, not by API key. Export is optional—into your own billing logic or Stripe, Lago, Orb, Metronome, and similar systems. FluxMeter does not claim to replace them, and it is not a complete billing or invoicing platform.

On the wire: a 202 on ingest means custody (usage was durably accepted), not settlement. ClickHouse is an audit cold store, not billing truth; Flink does usage aggregation, not billing. Meter every token. Attribute every cost. Stop at the usage line; leave invoicing to the billing layer.

Next steps

If “the key report is clear, but we cannot say which customer used the tokens” is the stuck point, check whether usage events already carry a customer dimension when they happen—before issuing more upstream keys, or asking for a bigger pooled report.

Boundaries and public comparisons: Compare

Touch the stack locally: `make demo` (see Docs)

Product and path facts: Architecture

Procurement-side companion: Upstream invoice ≠ customer-level usage

After you have usage lines, how to export: Export usage to Lago / Stripe / Orb / Metronome

Get the customer-level usage lines right first. Allocation, budgets, and invoicing only have a correct layer to stand on once you can see by customer.

Get the customer-level usage lines right first. Allocation, budgets, and invoicing only have a correct layer to stand on once you can see by customer.