Exact per-call metered billing without rounding losses
The article explains how a billing backend prices metered API usage to the cent, counting request and response bytes for live-key calls that succeed or fail on the customer's side. Because rounding each tiny call individually would either bill nothing or overcharge heavily, the system instead computes the cycle's total overage cost and debits each call the difference. This telescoping approach keeps fractional cents from being lost, so the cycle total is exact. A worked example with 50 GiB included and an overage rate of 600 cents per GiB shows a 51 GiB cycle costing exactly 600 cents. The method also supports tiered pricing, where each tier charges only for the bytes within its range, and discounts are applied before the single final rounding.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.



Discussion (0)
Log in to join the discussion and vote.
Log in