How to calculate the cost of an AI request

Formula for input and output tokens, recalculation of a series of requests and an example of estimating the cost of the received result.

Count the entrance and exit separately

Take your model's tariff and the query log. If you have prices per million tokens, multiply the number of input tokens by their rate, the number of weekends on the output tariff, add up and divide by a million. Separately enter paid tool calls if there are any. Cache entry needs its own column if the vendor charges it separately.

Example of contingent rates

Let one request use 4,000 input and 1,000 output tokens, at a notional rate of 2 and 8 monetary units per million, the cost is 0.016. If you need a second request, it's 0.032. The example shows how you calculate. For budget, take your provider's numbers and the single currency from your accrual history.

Check with the real result

Run twenty routine tasks. Summarize the transactions, including replays and queries that ended without a useful answer. Divide the amount by the number of results received; If the provider wrote off more than the calculated one, check the units of measurement, the cost of additional calls and the period matching. Separately count the employee's time for corrections: when choosing a model, it can be more expensive than the tokens themselves.

Related articles