Calculating Billing
Run a full line-item breakdown before issuing an invoice.
Why Calculate Before Invoicing
The calculation API lets you run the full billing computation — including tier breakdowns, flat fees, and all charges on a plan — without creating an invoice. This serves two purposes:
- Pre-invoice verification: Before charging a customer, confirm the calculated amount looks correct. Catch configuration errors before money moves.
- Customer-facing pricing previews: Build a live “what will I pay this month?” widget in your product, powered by real billing engine calculations.
POST /v1/pricing/calculate
The calculate endpoint runs a full billing calculation for a customer over a specified period and returns a detailed line-item breakdown.
| |
Response:
| |
All monetary amounts are in cents (integer). 18749 = $187.49.
The calculation_id is a stable reference to this specific calculation run. When you subsequently create an invoice with POST /v1/invoices, you can pass the calculation_id to skip recomputation and use the pre-calculated amounts directly. This ensures the invoice reflects exactly what you previewed.
Understanding Tier Breakdowns
For tiered and volume charges, the tier_breakdown array shows exactly how each usage band was priced. In the example above, 1,374,923 API calls were priced as:
- First 100,000: free ($0)
- Next 900,000 (100k–1M): $0.0001 each = $90.00
- Remaining 374,923 (above 1M): $0.00005 each = $18.75
Total for API calls: $138.49
This breakdown is included in the invoice and can be shown directly to customers in a usage report or invoice breakdown UI.
POST /v1/pricing/preview — For Pricing Pages
The preview endpoint is a lighter-weight version of calculate, designed for real-time pricing page use cases where you want to show customers what they’d pay at different usage levels without needing a real customer ID.
| |
Response:
| |
Use this on your pricing page to power an interactive “calculate your bill” widget. Pass hypothetical usage values from slider inputs and render the result without creating any customer records.
Ready to map your billing architecture?
In 30 minutes we identify your data contract gaps and show exactly what fixing the architecture looks like.