By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Waypoint now serves a handful of freight forwarders from one deployment: Northline, Bluewave and Harbor share the gateway, the retrieval index and the same provider account. The provider sends one invoice a month. Finance, and each tenant's own contract, need a number per tenant: what did they consume, what do they owe, and what happens when they run over?
Attribution starts earlier than billing. Step 20 put tenant context on every request, and step 11 recorded token and cost usage per request. That ledger is the raw material, but summing tokens is not chargeback. Chargeback is a contract with four parts: a versioned rate card, an allocation rule for shared cost, a reconciliation against the provider invoice, and a dispute path a tenant can follow. Without all four the number is a guess with decimals.
A budget is only real when it is enforced somewhere a request can feel. Waypoint runs three layers, and each has a different owner, scope and failure behaviour.
| Layer | Scope | Enforced at | When exceeded |
|---|---|---|---|
| Request budget | One call including retries | Gateway, before dispatch | Reject with a typed 429; nothing is dispatched or billed |
| Tenant period budget | Tenant day and month | Gateway, against a reserved ledger | Apply the pre-evaluated degrade plan or reject explicitly |
| Org pool | Shared provider account | Daily job plus the provider-side spend limit | Pause non-critical jobs and page the platform owner |
The order matters. The request budget is checked first so one hostile or looping prompt cannot reach the provider before the tenant ledger catches up. The tenant budget is next, and it must be checked against a rolling window that includes work in flight, not only work already settled. The org pool is the backstop: it catches the case where every tenant is individually inside its budget and the shared account is still about to auto-suspend.
Checking a budget and dispatching a call are two steps, and the time between them is where overdrafts come from. Two concurrent requests can each read the same remaining balance and each decide it is safe, so the tenant ends the minute over its cap. The fix is a reservation: estimate the request's cost from input tokens plus a bounded output estimate, reserve it atomically against the tenant window, dispatch, then settle the actual usage and release any unused reservation. Reservation and settlement are idempotent by request ID, so a retry settles once and a failed dispatch releases once.
from collections import defaultdict
# Pinned micro-USD per 1k tokens: the rate card version that was in force
# when each request was admitted. A later price change must not rewrite
# historical chargeback.
RATE_CARD = {
"waypoint-sim-1": {"input": 1000, "output": 2000},
}
usage_rows = [
{"tenant": "northline", "model": "waypoint-sim-1", "input_tokens": 1200, "output_tokens": 400},
{"tenant": "northline", "model": "waypoint-sim-1", "input_tokens": 800, "output_tokens": 200},
{"tenant": "bluewave", "model": "waypoint-sim-1", "input_tokens": 2000, "output_tokens": 600},
{"tenant": "harbor", "model": "waypoint-sim-1", "input_tokens": 500, "output_tokens": 100},
]
def request_cost_microusd(row: dict) -> int:
prices = RATE_CARD[row["model"]]
return (
row["input_tokens"] * prices["input"]
+ row["output_tokens"] * prices["output"]
) // 1000
def chargeback(rows: list[dict]) -> dict[str, int]:
totals: dict[str, int] = defaultdict(int)
for row in rows:
totals[row["tenant"]] += request_cost_microusd(row)
return dict(sorted(totals.items()))
print(chargeback(usage_rows))Every usage row stores the rate card version and the model snapshot that applied when the request was admitted. Chargeback is computed from those pinned prices, never from today's price list, or last quarter's statement would change every time a provider adjusts prices. Corrections are explicit journal entries with a reason and an approver, not silent recomputation.
Direct provider cost is the easy part. The shared cost is the one that causes arguments, so write the allocation rule down before the first invoice:
Once a month, compare three numbers in this order: the provider invoice, the internal usage ledger, and the chargeback total. The ledger should match the invoice within a stated tolerance; a delta is a bug in instrumentation, not a rounding gift. When the provider only exposes an aggregate, document the known unattributable gap, assign it to a named platform pool and work down its size over time.
Key takeaways
Chargeback needs a pinned rate card, a shared-cost allocation rule, invoice reconciliation and a dispute path; token sums alone are not billing.
Enforce budgets in three layers: per-request before dispatch, per-tenant rolling window with reservations, and the org pool as the backstop.
Reserve estimated cost before dispatch and settle actual usage afterwards, idempotent by request ID, so concurrent requests cannot overdraw a tenant.
Pin prices and model snapshots on every usage row; price changes and corrections become journal entries, never silent recomputations.
Reconcile invoice, ledger and chargeback monthly, publish the allocation key, and review variance in the weekly operating rhythm.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.