{"playbook":"Usage-based billing","url":"https://agentwranglers.se/playbook/usage-billing","updated":"2026-10-27","license":"https://creativecommons.org/licenses/by/4.0/","credit":"Required by the licence: credit Agent Wranglers with a link to the rule or playbook you used.","ids":"Each rule has an id, such as PAY-14, that never changes. Open a rule by its id at /r/PAY-14. Its revision changes whenever its content changes.","how":"Each rule's How and Measured text is on its own page: add .md to its url.","rules":[{"id":"USG-1","revision":"d98b0d6831ce","updated":"2026-10-27","name":"Give every usage event a key and count it once","level":"Required","risk":"money","applies":["payments"],"rule":"Give each usage event a key made from the work it bills, such as the request ID. Store it under a unique constraint, so a retry never bills twice.","check":"A test sends the same usage event three times, including once after a simulated crash. The usage table holds one row, and the period total counts it once.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/metering/idempotent-usage-events","related":["/playbook/payments/amounts-and-orders/idempotent-charge-creation","/playbook/api-design/reliability/idempotency-keys","/playbook/usage-billing/agentic-payments/http-402-payments"],"sources":["https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage-api","https://docs.stripe.com/api/idempotent_requests"]},{"id":"USG-2","revision":"541c7e01d292","updated":"2026-10-27","name":"Meter on the server after the work succeeds","level":"Recommended","applies":["payments"],"rule":"Record usage only on the server that did the work, after it succeeded, with the quantity it measured. Never take a quantity from the browser or the app.","check":"Search the API for request fields named quantity, tokens or units that reach the usage table. None do. A test makes a model call fail after the provider answers, and the result and the usage event are both saved or both missing.","check_type":"http","url":"https://agentwranglers.se/playbook/usage-billing/metering/server-side-metering","related":["/playbook/events/publishing-events/outbox","/playbook/files-and-media/quotas-and-cost/storage-quotas"],"sources":["https://cwe.mitre.org/data/definitions/602.html"]},{"id":"USG-3","revision":"00ec6e7a489f","updated":"2026-10-22","name":"Keep raw events and derive every total from them","level":"Recommended","applies":["payments"],"rule":"Keep every raw usage event for as long as you keep the invoice it fed. Compute period totals from the events, and never keep only a running counter.","check":"A job rebuilds last month's totals from raw events and compares them with the stored totals. They match for every customer and meter. The app's database role cannot run UPDATE or DELETE on the usage events table.","check_type":"command","url":"https://agentwranglers.se/playbook/usage-billing/metering/raw-usage-events","related":["/playbook/payments/invoices-and-records/payment-record-retention","/playbook/usage-billing/usage-on-invoices/usage-export","/playbook/usage-billing/usage-on-invoices/usage-credit-notes"],"sources":[]},{"id":"USG-4","revision":"d2433898c41c","updated":"2026-10-27","name":"Accept late events up to a fixed cut-off","level":"Recommended","applies":["payments"],"rule":"Bill each event by the time it happened. Accept late events for a fixed grace window, such as 24 hours after the period ends, then close the period.","check":"A test with a fixed clock sends an event that happened on the last day of the period and arrives 2 hours after it ends. It counts in that period. One that arrives 2 days later lands in the next period, and the closed invoice does not change.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/metering/late-usage-cutoff","related":["/playbook/events/consuming-events/event-order"],"sources":["https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage-api"]},{"id":"USG-5","revision":"6977aa075957","updated":"2026-10-22","name":"Match your usage totals with the provider before each invoice","level":"Recommended","applies":["payments"],"rule":"Before a usage invoice is finalised, compare your total per customer and meter with the total the billing provider holds. Hold the invoice when they differ.","check":"A test drops one event on the way to a sandbox provider. The reconciliation job finds the gap, resends the event and the draft invoice total then matches your sum. A second run sends nothing.","check_type":"command","url":"https://agentwranglers.se/playbook/usage-billing/metering/usage-reconciliation","related":["/playbook/payments/payment-events-and-reconciliation/payout-reconciliation"],"sources":["https://docs.stripe.com/billing/subscriptions/usage-based/configure-grace-period"]},{"id":"USG-6","revision":"1ae5080618d9","updated":"2026-10-27","name":"Keep credits in a ledger instead of a balance you overwrite","level":"Required","risk":"money","applies":["payments"],"rule":"Record every credit grant, use, refund and expiry as a new ledger row with a reason and a source ID. The balance is the sum of the rows.","check":"As the app role, run an UPDATE and a DELETE on the credit ledger. Both fail with permission denied. A nightly job compares each cached balance with the sum of its rows and alerts on any difference.","check_type":"command","url":"https://agentwranglers.se/playbook/usage-billing/credits-and-prepaid-balances/credit-ledger","related":["/playbook/pricing/ledger-and-accounting/double-entry-ledger","/playbook/payments/payment-events-and-reconciliation/payment-ledger","/playbook/customer-support/refunds-and-credits/goodwill-credits"],"sources":["https://docs.stripe.com/billing/customer/balance"]},{"id":"USG-7","revision":"064e96c78865","updated":"2026-10-22","name":"Hold credits before costly work and settle after","level":"Required","risk":"money","applies":["payments","ai-features"],"rule":"Before work whose cost is known only afterwards, such as a model call, hold the largest amount it can cost. Settle the hold to the measured cost when it ends.","check":"A test gives a customer credits for 3 calls and starts 10 at once. Exactly 3 run and 7 are refused before any provider call. A hold left open past its timeout is released by the next sweep.","check_type":"command","url":"https://agentwranglers.se/playbook/usage-billing/credits-and-prepaid-balances/credit-holds","related":["/playbook/data/transactions-and-concurrency/conditional-writes","/playbook/pricing/spend-caps-and-alerts/cap-overshoot"],"sources":["https://cwe.mitre.org/data/definitions/367.html"]},{"id":"USG-8","revision":"952f9a153778","updated":"2026-10-22","name":"Spend credits in a fixed order and show when they expire","level":"Recommended","applies":["payments"],"rule":"Spend the grant that expires first, then paid credits. Show each grant's amount and expiry date at purchase and on the billing page.","check":"A unit test gives an account a promotional grant ending in 7 days and a paid grant ending in 1 year, then spends credits. The promotional grant is used first. On the 8th day an expiry row removes its rest, and the paid grant is untouched.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/credits-and-prepaid-balances/credit-expiry-order","related":["/playbook/payments/tax/gift-card-vouchers","/playbook/payments/subscriptions/recurring-consent","/playbook/pricing/ledger-and-accounting/credit-breakage"],"sources":[]},{"id":"USG-9","revision":"4387b9878170","updated":"2026-10-27","name":"Decide in writing what happens at a zero balance","level":"Recommended","applies":["payments"],"rule":"Write down what each plan does when credits run out, such as stop, top up automatically or bill overage, and test each path.","check":"A table test runs one metered call at a zero balance for each plan. A stop plan refuses it with a clear message. A top-up plan charges once and runs it. An overage plan runs it and records the overage.","check_type":"command","url":"https://agentwranglers.se/playbook/usage-billing/credits-and-prepaid-balances/zero-balance-behaviour","related":["/playbook/pricing/spend-caps-and-alerts/customer-spend-cap","/playbook/payments/card-security-and-sca/off-session-payments"],"sources":[]},{"id":"USG-10","revision":"f3f187b48147","updated":"2026-10-27","name":"Letting customers spend or cash out credits outside your service","level":"Avoid","applies":["payments","eu-users"],"rule":"Never let credits be paid out as money, passed to other customers or spent with other sellers. The one exception is when you hold the licence for it.","check":"A search of the code and API finds no endpoint that pays credits out as money or moves them to another customer or seller. A feature that does is backed by a licence on file.","check_type":"http","url":"https://agentwranglers.se/playbook/usage-billing/credits-and-prepaid-balances/closed-loop-credits","related":["/playbook/payments/marketplaces-and-payouts/marketplace-funds"],"sources":["https://eur-lex.europa.eu/eli/dir/2009/110/oj"]},{"id":"USG-26","revision":"d146faaac41e","updated":"2026-10-27","name":"Show how a metered price is calculated before the customer pays","level":"Required","risk":"law","applies":["eu-users"],"region":["EU"],"rule":"Before an EU consumer signs up or buys credits, show each unit price and what counts as one unit. Add any fixed fee per billing period. Show it beside the order button.","check":"A browser test opens checkout for each metered plan as an EU consumer. The page shows each unit price and unit name from the price table, and the fixed fee, before the order button. A test fails when the page and the billing table differ.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/credits-and-prepaid-balances/metered-price-disclosure","related":["/playbook/usage-billing/usage-on-invoices/itemised-usage-lines","/playbook/payments/price-display-and-consumer-law/total-price-upfront"],"sources":["https://eur-lex.europa.eu/eli/dir/2011/83/oj"]},{"id":"USG-27","revision":"22b8a9e576aa","updated":"2026-10-27","name":"Decide when prepaid credits carry VAT","level":"Recommended","applies":["payments","eu-users"],"region":["EU"],"rule":"For each credit product, record whether VAT is due when the credits are sold or when they are spent. Keep the reason and your accountant's sign-off. Charge and report VAT at that point only.","check":"Every credit product in the catalogue has a VAT point of \"sale\" or \"spend\" and a sign-off date. A test buys and spends credits of each kind, and VAT appears on the invoice at the recorded point only.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/credits-and-prepaid-balances/credit-vat-point","related":["/playbook/payments/tax/gift-card-vouchers","/playbook/pricing/ledger-and-accounting/credit-breakage"],"sources":["https://eur-lex.europa.eu/eli/dir/2016/1065/oj"]},{"id":"USG-11","revision":"64f83a30c2f0","updated":"2026-10-27","name":"Charge each model call's cost to the customer who caused it","level":"Recommended","applies":["payments","ai-features"],"rule":"Store the cost of every model call, retry, embedding and tool call with the customer and the metered action it served. Then cost and revenue sit side by side.","check":"A query over last month's cost rows finds none without a customer ID or a shared cost label. A test makes a call that fails and is retried once, and both attempts appear under the same usage event key.","check_type":"command","url":"https://agentwranglers.se/playbook/usage-billing/margins-and-model-cost/cost-attribution","related":["/playbook/ai-features/latency-cost-and-fallbacks/cost-per-call","/playbook/infrastructure/cost-and-ownership/cost-per-request","/playbook/usage-billing/margins-and-model-cost/margin-guard"],"sources":["https://www.finops.org/framework/capabilities/allocation/"]},{"id":"USG-12","revision":"c8d5a158c492","updated":"2026-10-27","name":"Keep every metered price above its cost","level":"Recommended","applies":["payments","ai-features"],"rule":"Write a margin floor per plan, such as 40%. A test computes each metered unit's cost from the current model prices and fails when any price falls under the floor.","check":"The pipeline runs the margin test on every change to the model price table, the routing rules or the price catalogue. A test that doubles one model's price makes the margin test fail for the plans that use it.","check_type":"command","url":"https://agentwranglers.se/playbook/usage-billing/margins-and-model-cost/margin-guard","related":["/playbook/usage-billing/margins-and-model-cost/cost-attribution","/playbook/pricing/plans-and-prices/price-catalogue"],"sources":[]},{"id":"USG-13","revision":"1cd958ba3556","updated":"2026-10-27","name":"Alert when a customer costs more than they pay","level":"Recommended","applies":["payments","ai-features"],"rule":"Every day, compare each customer's model and infrastructure cost for the period with what they will be billed. Alert when cost passes 80% of the bill.","check":"A test customer on a flat plan makes calls whose cost reaches 85% of the plan fee. The next daily run alerts with that customer's ID, cost and bill. A customer at 50% is not listed.","check_type":"command","url":"https://agentwranglers.se/playbook/usage-billing/margins-and-model-cost/customer-margin-alert","related":["/playbook/scaling/exports-and-fair-share/per-tenant-limits"],"sources":["https://www.finops.org/framework/capabilities/unit-economics/"]},{"id":"USG-14","revision":"ed570cfe4b55","updated":"2026-10-27","name":"Recheck margins when a model or its price changes","level":"Recommended","applies":["payments","ai-features"],"rule":"Pin each model version in the price table. When a provider changes a price or retires a model, update the table and rerun the margin test before the change date.","check":"A test fails when the gateway calls a model name that is missing from the price table. The release calendar lists the retirement date of every model in the table.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/margins-and-model-cost/model-price-change","related":["/playbook/pricing/plans-and-prices/price-increase-notice"],"sources":["https://platform.claude.com/docs/en/about-claude/model-deprecations","https://developers.openai.com/api/docs/deprecations"]},{"id":"USG-19","revision":"155ab381fbe0","updated":"2026-10-22","name":"Show each metered charge as its own line","level":"Recommended","applies":["payments"],"rule":"Give each meter its own invoice line with the quantity, the unit, the unit price or tier, the period and the amount. Never bill usage as one lump sum.","check":"A test bills a customer for two meters, one with a free allowance and one with two price tiers. The invoice has one line per meter and tier, plus one for the allowance. The line amounts add up to the invoice total.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/itemised-usage-lines","related":["/playbook/usage-billing/credits-and-prepaid-balances/metered-price-disclosure","/playbook/payments/invoices-and-records/invoice-required-fields","/playbook/usage-billing/usage-on-invoices/committed-use-true-up"],"sources":["https://eur-lex.europa.eu/eli/dir/2006/112/oj"]},{"id":"USG-20","revision":"9ca42ee7f4f4","updated":"2026-10-22","name":"Let customers download the usage behind each invoice","level":"Recommended","applies":["payments"],"rule":"Offer a CSV download of the usage behind each invoice line. Give the event time, meter, quantity and the customer's own reference, such as a project.","check":"A test downloads the export for an invoice and sums the quantity per meter. Each sum equals the quantity on that meter's invoice line. The export contains no prompt text.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/usage-export","related":["/playbook/usage-billing/metering/raw-usage-events","/playbook/api-design/reliability/long-running-jobs"],"sources":[]},{"id":"USG-21","revision":"70077295644e","updated":"2026-10-22","name":"Credit back usage your own fault caused","level":"Required","risk":"money","applies":["payments"],"rule":"When an outage, a bug or a double count billed usage the customer never got, find every affected customer by query. Credit them all the same way.","check":"A test bills three customers twice for the same hour, then runs the correction script for that hour. Each paid invoice gets one credit note for the doubled amount. A second run adds nothing.","check_type":"command","url":"https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/usage-credit-notes","related":["/playbook/usage-billing/metering/raw-usage-events","/playbook/payments/invoices-and-records/credit-notes","/playbook/customer-support/refunds-and-credits/goodwill-credits"],"sources":["https://eur-lex.europa.eu/eli/dir/2019/770/oj"]},{"id":"USG-30","revision":"82690f6970e3","updated":"2026-10-27","name":"Name the tier model of every metered price","level":"Recommended","applies":["payments"],"stack":["stripe"],"rule":"Store with every tiered price whether it is graduated or volume. Graduated applies each tier's rate to the units inside it, and volume applies one rate to all units. Compute both in one tested function.","check":"A unit test bills 1,500 units on the price above in each mode and gets 14,000 and 12,000 cents. A test bills a quantity exactly on a tier boundary and gets the documented result. Every tiered price in the catalogue has a mode.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/tiered-or-volume","related":["/playbook/pricing/plans-and-prices/price-catalogue"],"sources":[]},{"id":"USG-31","revision":"82e35576d3bf","updated":"2026-10-27","name":"Bill early when unbilled usage passes a threshold","level":"Recommended","applies":["payments"],"stack":["stripe"],"rule":"Set an amount of unbilled usage, such as 500 euros or the plan fee. When usage passes it, invoice and charge at once instead of waiting for the period end. Lower it for new accounts.","check":"A test account with a threshold of 500 euros sends usage worth 510 euros in one day. An invoice for that usage is created and charged that day. A test with a failing card pauses the account's metered work.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/threshold-billing","related":["/playbook/payments/failed-payments-and-dunning/dunning-schedule"],"sources":[]},{"id":"USG-32","revision":"596cb9aadabd","updated":"2026-10-27","name":"Bill commitment shortfalls and overages from the contract","level":"Recommended","applies":["payments"],"rule":"Store each committed-use contract with its amount, period, what counts toward it and its overage price. At the period end, bill the shortfall or the overage on its own invoice line, computed by one tested function.","check":"A unit test bills a 12,000 euro commitment with 9,000 euros of usage and gets a 3,000 euro shortfall line. With 15,000 euros of usage it gets the overage at the contract rate. Every active contract has an amount, a period and an overage price.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/committed-use-true-up","related":["/playbook/pricing/spend-caps-and-alerts/usage-dashboard","/playbook/usage-billing/usage-on-invoices/itemised-usage-lines"],"sources":[]},{"id":"USG-22","revision":"025a157cb3c6","updated":"2026-10-27","name":"Track the agent payment protocols before you build on one","level":"Optional","applies":["payments"],"review_by":"2027-04-30","stack":["stripe"],"rule":"Before you build for an agent payment protocol, record its version, status and owner in the decision log. Recheck that entry every 6 months.","check":"The decision log has an entry for each agent payment protocol the app uses. Each gives the version and a check date less than 6 months old. A test fails when the entry is older.","check_type":"manual","url":"https://agentwranglers.se/playbook/usage-billing/agentic-payments/agent-payment-protocols","related":["/playbook/usage-billing/agentic-payments/http-402-payments"],"sources":["https://www.agenticcommerce.dev/","https://ucp.dev/latest/specification/overview/","https://datatracker.ietf.org/doc/draft-httpauth-payment/"]},{"id":"USG-24","revision":"85d070067599","updated":"2026-10-27","name":"Verify an HTTP 402 payment before doing the work","level":"Required","risk":"money","applies":["payments","public-api"],"spec_version":"x402 v2, MPP draft-httpauth-payment","review_by":"2027-04-30","rule":"If you charge per request with HTTP 402, as x402 and MPP do, settle each payment through a provider before the work runs. Refuse any payment proof used twice.","check":"A test calls a paid endpoint without proof and gets 402 with a price. A valid proof gets 200 once. The same proof sent again gets 402, and the work runs once.","check_type":"http","url":"https://agentwranglers.se/playbook/usage-billing/agentic-payments/http-402-payments","related":["/playbook/agents-as-users/quotas-and-pricing/cost-in-every-result","/playbook/usage-billing/agentic-payments/agent-payment-protocols","/playbook/usage-billing/metering/idempotent-usage-events"],"sources":["https://x402.org/x402-v2-launch/","https://datatracker.ietf.org/doc/draft-httpauth-payment/"]}]}