AI usage cost: how to calculate tokens and API spend
Almost every AI service sold through an API charges per token: one price per million input tokens (what you send) and another, usually higher, per million output tokens (what the model answers). To forecast the bill you need three numbers: the average size of each request, how many requests a day, and the price per million tokens of the model you chose.
The math
Input cost = input tokens ÷ 1,000,000 × input price, with the cache discount applied only to the share of input served from cache. Output cost = output tokens ÷ 1,000,000 × output price. Cost per request = (input + output) × (1 + retry rate). Then × requests per day = cost per day; × days of use = cost per month; × 12 = cost per year. Dividing monthly cost by active users gives AI cost per user, which should sit below the subscription price.
Example
Made-up, generic values, not any vendor’s: a model at $1.00 per million input tokens and $5.00 per million output tokens; 1,500 input and 400 output tokens per request; 40% of input served from cache at a 90% discount; 5% retries; 2,000 requests a day, 30 days a month. Effective input price: $1.00 × (1 − 40% × 90%) = $0.64. Input: 1,500 ÷ 1,000,000 × 0.64 = $0.00096; output: 400 ÷ 1,000,000 × 5.00 = $0.00200. With retries: $0.00296 × 1.05 = $0.00311 per request, $6.22 a day, $186.48 a month and $2,237.76 a year. With 500 users that is $0.37 per user; with a $9 subscription and $400 of fixed costs, $8.63 is left per user and 47 users cover the fixed costs.
Using it with care
Check prices on your provider’s current page: they change and vary by model. Measure the real tokens of a sample of requests instead of guessing. Long conversations resend the history on every turn, and tools, images and model reasoning can add tokens. If you only know size in words, use words mode with a factor measured in your language.
What the math leaves out
Size variation between requests, charges for images, audio, cache storage and tools, contract discounts, taxes and exchange rates. Cost is also not quality: compare the models’ answers on your task. Educational estimate, with no recommendation of any model or vendor.