# 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](https://pastagi.com). 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
```