Provider invoices arrive per account. Finance needs the opposite view: cost by project, by period, with a limit that actually holds and a number that can be traced back to the calls that produced it. Between those two views sits a gap that most organisations fill with a spreadsheet, a monthly meeting and a fair amount of guessing.
This article describes a model that closes the gap. It is the one we implemented in the Axium gateway, but the reasoning applies whether you buy a gateway, build one, or are still deciding. It covers four things in order: what to meter, how to attribute it, how to cap it, and how to reconcile it with the invoice that finance actually pays.
Why the invoice cannot answer the question
A provider bills the account that owns the key. In a typical company that account is shared: one OpenAI organisation, one Azure subscription, one Google project, used by every team that asked for access. The invoice can tell you which model cost what. It cannot tell you which product did, because the provider has no idea how your organisation is structured.
The usual workarounds each break in a predictable way:
- One provider account per team. Attribution becomes clean, and everything else becomes worse: N contracts, N sets of keys, N data-processing assessments, and no way to apply one policy to all of them.
- Tagging at the provider. Some providers let you label keys or projects. The labels live in the provider's console, follow the provider's model of the world, and disappear the day you add a second provider.
- Estimating from application logs. Every team logs tokens differently, if at all. Nobody logs the calls that failed halfway, and nobody logs the experiments run from a laptop.
All three fail for the same reason: the cost is computed after the fact, from data that was never designed to be a ledger. The fix is to compute it at the point where every call already passes, at the moment the call happens.
Step 1: meter every call, at the time of the call
The unit of account is the individual request. For each one, the gateway needs three numbers and one price.
Token counts from the provider, not from an estimate. Every major provider returns a usage block in the response: input tokens, output tokens, and increasingly cached and reasoning tokens. That block is the number the provider bills on, so it is the number to record. Tokenising the prompt yourself gives you an estimate that drifts with every model release. Streaming needs care: some APIs only report usage in the final frame, and some only if the client asks for it. Our gateway adds the usage flag on streamed OpenAI-style requests so that a streamed call is metered exactly like a non-streamed one.
A price per model, per direction. Input and output tokens are priced differently, often by a factor of four or more, so a single "price per token" is wrong by construction. We store a price per million input tokens and per million output tokens for each deployed model, with six decimals of precision. That precision matters more than it seems: a cheap model can cost fractions of a cent per call, and rounding each call to two decimals silently erases the long tail.
Cost stored with the call, not recomputed later. Prices change. If the cost table is a join between token counts and today's price list, every historical report changes the day a provider cuts its prices. We write the computed cost onto the request record when the call settles, so a report for March still says what March cost.
Two edge cases deserve an explicit decision rather than a default:
| Situation | Tempting default | What we do, and why |
|---|---|---|
| A model has no price configured | Record cost as 0 | Record cost as null in the trace. "Unknown" is not the same as "free", and a dashboard full of zeros hides the gap. |
| Cached input tokens (discounted by most providers) | Apply an assumed discount | Bill cached input at the full input rate and record the cached count separately. Guessing a discount understates the bill; overstating it slightly is the safer error for a budget. |
| Request answered from the gateway's own cache | Charge it as a normal call | Record no cost. The provider was never called, so there is nothing to bill. |
| Provider returned an error | Ignore it | Record the call with its status. Failed calls are not billed by the provider, but they are evidence, and a spike of them is usually the first sign of a misbehaving client. |
The point of this table is not that our choices are the only correct ones. It is that each of these situations will occur, and if nobody decides, the reporting tool decides for you, invisibly.
Step 2: attribute it to something finance recognises
Once every call carries a cost, the question becomes whose cost it is. There are two layers, and confusing them is the most common design mistake.
The enforcement unit: the project
A project is the thing that owns a budget. In Axium it is called a proxy app: a named application with its own keys, its own allowed models, its own policies and its own budget. Every API key belongs to exactly one project, so every call is attributable before the request body is even read. There is no "shared" key whose cost has to be split afterwards. (Why that matters beyond cost is the subject of a separate piece: one key per project.)
The project should map to something finance already has a line for: a product, a cost centre, a client engagement. If your projects map to teams and your budget lines map to products, you will spend every month translating between the two.
The analysis dimensions: user, feature, tag
Inside a project, finance rarely needs more granularity, but the people running the project do. Which feature is driving the cost? Which internal user ran the batch job that tripled last Tuesday's spend? These are analysis questions, not enforcement questions, so they belong in metadata, not in the key structure.
We let the caller attach them per request with headers:
POST /proxy-apps/{app}/openai/v1/chat/completions
Authorization: Bearer ax_…
x-axium-user-id: u-48213
x-axium-meta-tag: claims-summary
x-axium-env: staging
x-axium-user-id and x-axium-meta-tag are first-class fields on the trace; any other x-axium-* header is stored as a free-form tag. The caller does not need a new key to start a new feature, and the platform team does not need to be involved.
Rule of thumb: if you would ever want to stop spending on it, it is a project. If you only want to understand spending on it, it is a tag.
Step 3: cap it, and be precise about what the cap means
A budget that only produces a report is a forecast. A budget that stops calls is a control. Finance and audit both care about the difference, so it is worth being exact about how the control behaves.
Periods follow the calendar. We support daily, weekly and monthly budgets, aligned to midnight, Monday and the first of the month in the installation's timezone. A rolling 30-day window sounds more precise, but it never matches a planning cycle or an invoice, and nobody in finance can tell you on which day a rolling window "resets". A budget with no period is an absolute limit, useful for a pilot with a fixed allocation.
At the cap, the call is refused, not degraded. When a project's spend for the current period reaches its limit, the next request is rejected before it is routed to any provider. The client receives an HTTP 429 in the error shape of the SDK it is already using (an insufficient_quota error for OpenAI clients, RESOURCE_EXHAUSTED for Gemini, a rate-limit error for Anthropic), so existing retry and error handling keeps working. The refusal is recorded in the trace with the reason budget_exhausted, which means "who was blocked, when, and why" is itself auditable.
The cap is checked before the call, and the cost is known only after it. This is the subtle part, and most products gloss over it. The price of a call depends on how many tokens the model generates, which is not known until it finishes. So the sequence is: check that the period's spend is below the limit, forward the call, and add its cost atomically when it settles. Spend is never lost or double-counted, even under concurrency. But if twenty requests are in flight when the limit is crossed, all twenty complete.
The overshoot is therefore bounded, and you can size it:
maximum overshoot ≈ concurrent requests in flight × cost of the most expensive single call
A project running ten concurrent requests against a model whose worst-case call (maximum output tokens) costs €0.40 can exceed its cap by about €4. For a monthly budget of €1,200 that is irrelevant. For a €10 daily budget on a pilot it is not, and the right answer is to set max_tokens on the client or the cap slightly lower, not to pretend the cap is exact.
The alternative, reserving the worst-case cost of every request before forwarding it, gives a hard guarantee at the price of rejecting legitimate calls whenever the reservation is pessimistic, which with long-output models is most of the time. We chose the bounded overshoot and documented it. Whichever you choose, write the behaviour down: an auditor will accept a documented, bounded tolerance far more readily than an undocumented "it never goes over" that turns out to be false.
Step 4: reconcile with the invoice
The gateway's ledger and the provider's invoice will not match to the cent. They should match to within a known, explainable difference. Before the first month-end, list the sources of that difference so nobody has to rediscover them under pressure:
- Cache discounts. If the provider discounts cached input and your ledger bills it at the full rate (as ours does), the ledger will be slightly higher than the invoice. That is the intended direction of the error.
- Traffic that did not go through the gateway. Any key still used directly against the provider appears on the invoice and nowhere in the ledger. The difference between the two is, in practice, the best detector of shadow usage you will ever have.
- Price changes mid-period. If a provider changes its price and the model's price in the gateway is updated a week later, calls in that week are recorded at the old price. Update prices on the day they change, and keep a note of when you did.
- Currency and taxes. Providers mostly bill in USD; finance reports in EUR. Convert at a documented rate at period close, not per call. Taxes and credits belong on the invoice side only.
- Batch and committed-use discounts. Contractual discounts apply at invoice level. Keep list prices in the gateway and apply the contractual discount as a single reconciliation line, so project-level numbers stay comparable over time.
A reconciliation that fits on one page, with these five lines and a residual below one or two percent, is what "survives the audit" means in practice. It shows the control is complete (everything on the invoice is accounted for), accurate (the numbers agree), and understood (every difference has a cause).
What finance actually receives
Put together, the monthly view that finance needs is not a dashboard. It is a table:
| Project | Owner | Period | Budget | Spend | Utilisation | Calls refused at cap |
|---|---|---|---|---|---|---|
| claims-assistant | Claims Ops | Oct 2026 | 1,200.00 | 1,087.42 | 91% | 0 |
| kyc-document-check | Compliance | Oct 2026 | 600.00 | 600.31 | 100% | 214 |
| internal-search | IT | Oct 2026 | 300.00 | 112.90 | 38% | 0 |
Illustrative figures.
Each line is a cost centre they recognise, a limit someone approved, and a number that drills down to individual calls. The second line is the interesting one: the cap held, 214 calls were refused, and the €0.31 above the limit is the bounded overshoot described above. That line is the evidence that the control works, which is precisely what an auditor will ask to see.
A checklist before you start
- Every key belongs to exactly one project, and every project maps to a budget line finance recognises.
- Token counts come from the provider's usage report, including for streamed calls.
- Input and output are priced separately, per model, with at least six decimals.
- Cost is written onto the call record when it settles, not recomputed from a current price list.
- Unpriced models show as unknown, not as zero.
- Every project has a period and a limit, or a documented reason it does not.
- The behaviour at the cap, including the overshoot bound, is written down.
- Month-end reconciliation against the invoice has a fixed list of expected differences.
None of this requires sophisticated tooling. It requires one place where every call passes, a decision on each of the edge cases above, and the discipline to write those decisions down. The AI gateway overview explains why that place is worth having for reasons beyond cost; if you want to see this model running on your own traffic, you can book a demo.