Estimate prompt token cost from a supplied rate
Check units and version numbers as you type. · 173 words
A token is a small piece of text used by the model, often a word or part of a word. The model's tokenizer decides the exact count. Cost comes from multiplying input tokens by the supplied input rate. Suppose a shopping assistant's prompt uses 12,500 input tokens and the rate is $2 per 1,000,000 input tokens. The estimated prompt cost is 12,500 / 1,000,000 x $2 = $0.025. This estimate concerns prompt tokens only. Output tokens, cached input, tool calls, and taxes may be billed separately.
For a second example, a library sends 400 catalog questions to a model. Each prompt is 3,000 tokens, so total input is 400 x 3,000 = 1,200,000 tokens. At a supplied rate of $3 per 1,000,000 tokens, the prompt cost is 1.2 x $3 = $3.60. A cost estimate becomes unreliable if token counts are guessed, so count with the provider's tokenizer and record the rate version. For budgeting, also test a larger prompt and reserve a margin for retries. A failed retry can consume input again.
Check your recall
At a rate of $4 per 1,000,000 input tokens, what is the prompt cost for 25,000 input tokens?
Check your answer
The cost is 25,000 / 1,000,000 x $4 = $0.10.
Sources and credits
Original KeyTouch lesson. Background reading · Google · Rules of Machine Learning.