Investing
Cost of one request
Each token count is divided by a million to convert it into units of the quoted price, then multiplied by that price. The two sides are added because both are billed.
Last updated
The Formula
cost = (t_in / 1,000,000) x p_in + (t_out / 1,000,000) x p_out
Each token count is divided by a million to convert it into units of the quoted price, then multiplied by that price. The two sides are added because both are billed.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| t_in | Prompt tokens | tokens | Tokens sent with the request. |
| p_in | Input price | currency | Cost per million prompt tokens. |
| t_out | Completion tokens | tokens | Tokens returned by the model. |
| p_out | Output price | currency | Cost per million completion tokens. |
| c | Cost per request | currency | The full cost of one call. |
What Each Symbol Means
t_intokens
Prompt tokens
Tokens sent with the request.
p_incurrency
Input price
Cost per million prompt tokens.
t_outtokens
Completion tokens
Tokens returned by the model.
p_outcurrency
Output price
Cost per million completion tokens.
ccurrency
Cost per request
The full cost of one call.
See It Worked With Real Numbers
A formula on its own does not tell you which number goes where. The how to calculate ai api costs page applies this equation to a concrete case, shows every intermediate step, and names the mistakes that produce a wrong answer even when the algebra is right.
Where This Formula Appears
This equation is the working core of How To Calculate AI API Costs, filed under Finance. Every number the guide produces comes from substituting into this one line.
Common Questions
What is the formula for Cost of one request?
The formula for Cost of one request is cost = (t_in / 1,000,000) x p_in + (t_out / 1,000,000) x p_out. Each token count is divided by a million to convert it into units of the quoted price, then multiplied by that price. The two sides are added because both are billed.
What does each symbol in Cost of one request stand for?
t_in is prompt tokens; p_in is input price; t_out is completion tokens; p_out is output price; c is cost per request.
What units should I use with Cost of one request?
Substitute t_in in tokens, p_in in money (any currency, as long as every money input uses the same one), t_out in tokens, p_out in money (any currency, as long as every money input uses the same one), c in money (any currency, as long as every money input uses the same one). Convert every input to those units before you start, because the equation only returns the right answer when the units on both sides agree.
What is a common mistake when using Cost of one request?
Counting only the completion tokens. The prompt is billed as well, and on retrieval-heavy designs it is the larger half. A design that returns few tokens can still be expensive because of what it reads.