ai-serving-cost: Restate an AI API bill from tokens, rates, and cache share

[ library, math, mit ] [ Propose Tags ] [ Report a vulnerability ]

An API bill is a token count times a rate, minus whatever the cache knocks off, plus a per-request floor. These functions compute that math directly: price a single request from its input and output tokens, price the cache discount at a given volume, and scale a per-request cost to a 30-day monthly bill. An audit can restate the invoice line by line instead of trusting the provider's summary.

Companion to Pastagi, which publishes AI cost audits and serving math. Five pure functions, no dependencies beyond base.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0
Change log CHANGELOG.md
Dependencies base (>=4 && <5) [details]
License MIT
Copyright 2026 Poket Dev LLC
Author Poket Dev
Maintainer hello@poketdev.com
Uploaded by PoketDev at 2026-11-02T02:54:10Z
Category Math
Home page https://pastagi.com
Bug tracker https://github.com/scrapertweeter3-prog/ai-serving-cost-hs/issues
Source repo head: git clone https://github.com/scrapertweeter3-prog/ai-serving-cost-hs
Distributions
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-11-02 [all 1 reports]

Readme for ai-serving-cost-0.1.0

[back to package description]

ai-serving-cost

Restate an AI API bill from tokens, rates, and cache share, the way a cost audit would: input and output priced separately, the cache discount taken off the input side, the per-request floor added back.

Rates are per million tokens. A workload of 10,000 input and 500 output tokens at $3 and $15 per million, with a $0.0005 per-request fee, costs $0.038 uncached and $0.029 at a 30 percent cache hit rate. At 20,000 requests a day that is $17,400 for the month, and the cache is saving $60 of every $150 the input side would otherwise pay on 50 million tokens.

The package follows the serving-math method used on Pastagi. It depends only on base.

Example

requestCost 10000 500 3.0 15.0 0.3 0.0005  -- 0.029
cacheSavings 50000000 3.0 0.4              -- 60.0
monthlyBill 0.029 20000                    -- 17400.0