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.
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.