Engineering

Per-Customer Usage Tracking and Billing for AI Features

THE SHORT ANSWER

Track AI usage at the customer and product-action level, then reconcile it with provider records. A provider invoice tells you what your business spent; it does not automatically tell you what each customer owes. Reliable billing needs an application ledger, stable event identifiers and a clear rule for failed or repeated attempts.

What should a usage event contain?

Record customer ID, feature, operation ID, attempt ID, model, timestamp, usage categories, provider cost and customer charge. Keep provider cost separate from your selling price. A discount from your supplier does not have to change a customer’s contracted price.

Version both the tariff and the product pricing rule. If you recalculate last month’s usage using today’s rates, historical invoices can drift.

How do you avoid charging twice?

Use an immutable usage event identifier and enforce uniqueness when settling an operation. If the same webhook or completion message arrives twice, process it once. Record adjustments as new ledger entries rather than rewriting history invisibly.

Distinguish an attempt from a billable customer outcome. Your application may pay for a failed attempt and a successful retry while charging the customer only once. Decide that policy explicitly and reflect it in your margin calculation.

How can budgets stop overspending under concurrency?

Reserve estimated spend before admitting work. If a customer has $1 remaining and ten workers each independently approve a $0.30 task, the account can overspend before any result is recorded.

An atomic reservation prevents that race. On completion, replace the reservation with actual usage and release the remainder. Keep uncertain operations pending until reconciled instead of assuming a timeout means zero cost.

Should customers pay per token or per feature?

Token billing offers a close relationship to supplier cost but can be difficult for ordinary users to predict. Feature credits, such as one report or one document analysis, are easier to understand but expose your business to variation in document size and workflow complexity.

A hybrid can work: a subscription includes a defined allowance, with explicit limits on document size and additional usage. Price from observed distributions, including expensive customers, rather than the average alone.

How do you calculate sustainable margins?

If a feature sells for $0.02 and its attributable variable cost is $0.006, gross margin on that feature is 70%: ($0.02 − $0.006) / $0.02. This illustrative calculation should include inference, retrieval, storage, payment costs and support costs that you classify as variable.

Do not confuse a 70% margin with a 70% markup. They use different denominators.

What does Tokely contribute?

Tokely billing documentation describes usage-based charging, balance and reservations. Use these records to reconcile supplier cost. Your SaaS still needs its own customer ledger and billing policy.

Start with one billable feature, define its acceptance rule, and estimate supplier costs using Tokely pricing. Expand billing only after the ledger can explain every charge and adjustment.

More clarity. Better decisions.Back to top ↑
PUT IT INTO PRACTICE

Find your model.
Make your next move.

Compare current prices, choose a model, and build with one API.