Research-backed calculator guide
AI SaaS Token Metering: Turn Provider Usage into Customer-Billable Units
Design an AI SaaS usage-based billing meter that separates provider token cost, customer billable units, and contribution margin—with a worked example and implementation checklist.
Quick answer
AI SaaS usage-based billing works best when you do not make one token counter serve three jobs. Keep a raw provider-cost ledger, a customer-billable usage ledger, and a margin ledger. The raw ledger records what each provider actually reports: model, request, input tokens, cached input or cache reads, output tokens, tool or media units, status, and provider price version. The customer ledger converts successful product value into a stable unit such as an AI action, workflow run, document, minute, or credit. The margin ledger joins the first two with infrastructure and support costs.
This separation lets you change provider, model, cache policy, or customer pricing without rewriting historical invoices. It also makes disputes traceable. A customer can ask why they were charged 18 AI actions, while Finance can ask why provider COGS rose. Those are related questions, but they are not the same meter.
A billing meter event is an action a customer takes in your system. Stripe’s official API reference describes meter events as usage records associated with a billing meter that defines the event payload and aggregation rule.[1] For an AI SaaS product, send a durable event after the product has decided what happened, then retain the provider response as cost evidence. Do not infer an invoice only from a tokenizer estimate.
What token metering should measure
A provider token count is an input to cost accounting, not automatically a good customer price metric. One request may contain ordinary input tokens, cached input tokens, output tokens, reasoning or thinking tokens, image tokens, audio units, tool calls, and retries. Rates can vary by category, model, processing mode, region, or contract. OpenAI’s pricing page, for example, presents separate input, cached-input, and output units and also lists non-token tools and processing modes.[2] Anthropic documents base input, cache writes, cache hits or refreshes, and output as different pricing categories.[3]
Record the provider’s usage object as close to the API response as possible. A practical raw event has these fields:
event_id: a globally unique identifier for deduplication.customer_idandworkspace_id: the account and billing owner.request_idandidempotency_key: the request lineage and retry guard.provider,model,model_version, andservice_tier: the rate-card dimensions.input_tokens,cached_input_tokens, andoutput_tokens: separate quantities, not one total.tool_units,image_units,audio_seconds, or other non-token quantities when applicable.request_status: succeeded, failed, cancelled, timed out, or refunded.occurred_atandreceived_at: both the product event time and ingestion time.rate_card_version: the prices used for the cost calculation.
The rate_card_version matters because provider prices and model catalogs change. Date every pricing observation and store the unit. “$2” is not auditable without knowing whether it means $2 per million input tokens, $2 per thousand requests, or $2 per minute. In this article’s examples, dollars are USD and token rates are per 1,000,000 tokens. The rates below are illustrative internal assumptions, not vendor quotes; check current provider pricing before deploying a rate card.
Do not use a preflight token count as the final billed quantity. Anthropic’s token-counting documentation says the endpoint returns an input-token estimate and warns that actual input tokens can differ; it also notes that automatically added system tokens are not billed.[4] Use preflight counts for routing, budget checks, and rough forecasts. For reconciliation, prefer the provider’s final response usage and invoice or usage export.
The three-ledger design
Ledger 1: provider cost. This is the technical cost of serving the request. Rate each provider category independently:
provider_cost = (input_tokens × input_rate) + (cached_input_tokens × cache_rate) + (output_tokens × output_rate) + other_provider_charges
If a provider reports cache writes separately from cache reads, keep both categories. If the response contains tool, image, audio, or search charges, add them as separate line items. A failed request may still have provider cost, so status should not be the only filter for cost capture.
Ledger 2: customer usage. This is the value metric your contract promises. It may be one AI action per completed workflow, one credit per weighted unit, one document processed, or a blended plan allowance. A customer unit should be stable enough to explain on an invoice. “1,842,612 raw tokens” may be accurate but can be a poor product metric when customers think in completed reports or workflow runs.
Ledger 3: contribution margin. Join provider cost to other variable costs such as inference infrastructure, vector retrieval, storage, payment fees, and human review. Then compare total variable COGS with customer revenue. A token meter can be correct while the plan is unprofitable if every request also triggers a costly retrieval or review step.
Chargebee’s usage-billing documentation illustrates why the operational layer needs more than a counter: it describes ingestion, metering, idempotency, prepaid-credit balances, alerts, overages, and auditable usage records as connected controls.[5] Whether you build or buy those capabilities, model them explicitly in your event and billing schemas.
How to choose the customer-billable unit
Start with the product outcome, then test whether the unit correlates with cost. Use raw tokens as the customer unit when customers are technical, can forecast token demand, and accept variable input/output rates. Use credits when the product combines models or tools and you need one wallet. Use an action or workflow unit when customers buy a completed result and the implementation can absorb moderate provider-cost variation.
A hybrid design is often practical: a monthly base fee includes a number of credits, each credit is consumed by a weighted action, and overage is charged after the allowance. Publish the conversion rule. For example, one “standard answer” may equal one credit, while a long-context answer equals three credits. Store the rule version on each customer usage event so a future pricing change does not recalculate old invoices.
Avoid hiding material cost differences. If one customer uses a cheap model and another uses a premium reasoning model, a flat action price can compress margin. Options include model-specific credit weights, a premium-model surcharge, plan entitlements, or a customer-visible token add-on. Make the trade-off visible rather than silently subsidizing the most expensive path.
The meter also needs a policy for retries and partial success. A provider retry that produces no customer-visible result may belong in provider COGS but not customer usage. A successful fallback that does produce the result may create one customer action but two provider-cost records. That is exactly why the two ledgers must not be collapsed.
Worked cost example
Assume a multi-tenant AI SaaS product has 100,000 successful workflow runs in one month. The product sells one customer-facing AI work unit per successful run. These are internal planning assumptions, not quoted market prices:
| Step | Assumption or input | Calculation | Output |
|---|---|---|---|
| 1. Customer usage | 100,000 successful workflow runs; 1 work unit per run | 100,000 × 1 | 100,000 billable work units |
| 2. Provider input cost | 2,400 ordinary input tokens per run at $2.00/M tokens | 100,000 × 2,400 / 1,000,000 × $2.00 | $480 |
| 3. Provider cache cost | 600 cached input tokens per run at $0.50/M tokens | 100,000 × 600 / 1,000,000 × $0.50 | $30 |
| 4. Provider output cost | 900 output tokens per run at $8.00/M tokens | 100,000 × 900 / 1,000,000 × $8.00 | $720 |
| 5. Raw provider COGS | Steps 2–4 | $480 + $30 + $720 | $1,230 |
| 6. Other variable COGS | Retrieval, hosting, storage, payment, and review allocation | Planning assumption | $1,050 |
| 7. Total variable COGS | Provider plus other variable COGS | $1,230 + $1,050 | $2,280 |
| 8. Customer price | $0.10 per work unit | 100,000 × $0.10 | $10,000 revenue |
| 9. Contribution margin | Revenue less total variable COGS | $10,000 − $2,280 | $7,720, or 77.2% |
The same example exposes why a single meter is dangerous. If you only record total tokens, you lose the difference between 240 million ordinary input tokens, 60 million cached input tokens, and 90 million output tokens. If you only record customer work units, Finance cannot explain why provider spend changed. If you only record provider cost, Product cannot tell whether a customer paid for a completed run, a failed attempt, or an internal retry.
For a margin-safe plan, recalculate this example by segment. A power user may have a much higher output-to-input ratio. A premium model may use a different rate card. A long-context customer may create more cache writes. Keep the same event shape, but group margin reports by model, plan, workspace, region, and workflow type. Do not average away the traffic shape that creates the loss.
Implementation sequence and controls
- Define the product event. Decide what counts as one customer outcome. Write the success, failure, cancellation, refund, and retry policy before selecting a billing vendor.
- Capture raw provider usage. Store the full usage response or a lossless normalized copy. Preserve model and category dimensions, not just a total token count.
- Make ingestion idempotent. A retry must not create two invoice rows. Enforce uniqueness on the product event and provider request lineage, and retain a logged duplicate decision.
- Rate provider cost separately. Version the rate card and calculate each category with explicit units. Re-rate only through a controlled adjustment process when a provider correction arrives.
- Emit the customer meter. Create one billable event only when the product outcome meets the contract rule. Link it to all contributing provider events so a support agent can trace the invoice line backward.
- Aggregate with a visible window. Show accrued usage and estimated charges before close. Set alerts for credits, overages, unusual spend, and margin deterioration.
- Reconcile to the provider. Compare your event totals with provider usage exports or invoices by day, model, and category. Track late events, refunds, and unexplained variance rather than overwriting history.
- Audit the invoice. Store the pricing-rule version, unit conversion, customer plan, included allowance, overage rate, and adjustment reason on the invoice or its audit trail.
You can use the AI API invoice reconciliation calculator to structure the estimate-versus-actual comparison, and the AI Agent Cost Calculator when the product cost includes more than model tokens. For alert and intervention economics, compare the result with the AI observability ROI calculator.
Run your scenario
Turn this framework into an editable estimate.
Use dated, source-linked assumptions and see cost per request, successful task and month.
Common failure modes
Billing from tokenizer estimates. Estimates are useful before a call, but provider-reported usage is the reconciliation record. Keep both fields and label them clearly.
Charging raw tokens without category separation. Input, cached input, and output can have different rates. A single total makes margin and disputes harder to explain.
Counting attempts instead of outcomes. Retries and timeouts can inflate customer usage. Decide whether an attempt, completion, or accepted result is billable.
Applying today’s price to old events. Store an effective date and rate-card version with each rated record. Historical invoices should not silently change because a model price changed.
Ignoring non-token cost. Retrieval, images, audio, hosted tools, storage, and human review can dominate the bill for some workflows. Join them to the same customer outcome.
No late-event policy. Batch jobs and delayed provider exports can arrive after invoice close. Define a cutoff, accrual method, adjustment note, and customer notification policy.
Frequently asked questions
Should an AI SaaS product bill customers by tokens or by actions?
Use tokens when the customer understands and can forecast token consumption. Use actions, workflows, documents, or credits when customers pay for an outcome and the product hides provider complexity. In both cases, retain raw tokens internally for cost attribution and reconciliation.
How do I calculate provider cost from input and output tokens?
Rate each category separately, then sum the results: ordinary input tokens times the input rate, cached input tokens times the cache rate, output tokens times the output rate, plus any other provider charges. Divide tokens by the provider’s stated unit, commonly 1,000,000 tokens. Confirm the unit and price effective date before publishing a customer rate.
Are preflight token counts enough to invoice a customer?
Usually no. A preflight count is an estimate used for routing or a budget check. The final response may include different usage, cache categories, tool activity, or provider-specific accounting. Use the provider’s final usage data and retain the preflight estimate only as an explanatory field.
How should retries affect a customer bill?
Separate provider cost from customer usage. A retry can create additional provider cost without creating another customer-visible outcome. If the retry succeeds after the first attempt failed, you may record one customer action linked to multiple provider-cost events. Document the rule in your pricing terms and make adjustments auditable.
Can one credit represent different models?
Yes, but use a published conversion or weight. For example, a standard model action might consume one credit and a premium reasoning action three credits. Version the conversion rule on each event and review the weight against observed COGS. Otherwise, customers can receive inconsistent value and your margin report can become misleading.
What should I show on the invoice?
Show the customer-facing unit, quantity, rate, included allowance, overage, credits applied, and billing period. A technical customer may also value a usage breakdown by model or workspace. Keep provider secrets and internal rates private when necessary, but retain the raw-to-billable mapping for support and audit use.
How often should usage and margin be reconciled?
Use near-real-time or daily aggregation for customer visibility and guardrails, then perform a formal period reconciliation against provider exports or invoices. High-volume products should monitor variance continuously. A month-end-only process can discover a duplicate-event or late-data problem after the customer has already received a surprise bill.
Primary sources checked
Pricing and product behavior can change. These sources support the time-sensitive claims in this guide; verify current provider terms before committing spend.