To calculate the cost of a single LLM prompt, you tokenize the input text with the model's BPE tokenizer, multiply the resulting token count by the per-million-token price divided by one million, and then multiply that single-request cost by your expected request volume. This matters because billing is per token, not per character or word, so the tokenizer's output β not your intuition about text length β is the number that drives the invoice.
From Tokens to Dollars: Why BPE Counts Drive API Bills
Large language models don't read text the way you do. Before any computation happens, the input string is converted into a sequence of tokens β the atomic units the model actually processes. Most modern models use Byte Pair Encoding (BPE), a compression-style algorithm that starts from raw bytes and repeatedly merges the most frequent adjacent pair into a single unit, building a vocabulary of common subwords, words, and punctuation fragments. A frequent word like "the" typically becomes one token; a rare word like "tokenization" might split into two or three; an emoji or an unusual identifier can consume several tokens because it decomposes into bytes first.
The billing consequence is direct: providers price per token, usually quoted as a rate per million tokens, and the meter runs on the tokenizer's output. Two prompts of identical character length can cost different amounts if one is dense in rare words, code, or non-Latin script and the other is plain English prose. Per-million pricing is just a normalized rate β it tells you the cost of one million tokens, so dividing by a million gives you the cost of a single token, and multiplying by your prompt's token count gives you the cost of that prompt. Everything else in this article is arithmetic layered on that one relationship.
One more distinction before moving on: input tokens (your prompt, including any system instructions and retrieved context) and output tokens (the model's generated response) are usually priced at different rates, and output is typically the more expensive side. This worked example focuses on input, since that is the part you can count exactly before sending a request.
Step-by-Step: Counting Input Tokens with a BPE Tokenizer
You need two things: the tokenizer that matches your target model's vocabulary, and a token count. Tokenizer implementations are available in common language ecosystems, and most expose an encode function that returns a list of integer token IDs; the length of that list is your count. If you don't have the exact tokenizer, a widely used open BPE tokenizer is a reasonable approximation, but treat cross-tokenizer counts as estimates β vocabularies differ, so counts for the same string differ.
The procedure, in pseudocode:
count = len(tokenizer.encode(prompt_text))
cost_per_token = price_per_million / 1_000_000
request_cost = count * cost_per_token
A few practical details. First, count the entire input payload, not just the user's question: system prompts, few-shot examples, conversation history, and any retrieved documents all occupy tokens and all get billed. Second, whitespace and formatting count β a newline or indentation in a code block may be one or more tokens. Third, be careful with the arithmetic: price_per_million / 1_000_000 gives dollars per token, which is a very small number (a rate of 3 per million yields 0.000003 per token), so keep full precision until the final rounding or you'll introduce visible error at scale. A prompt of 1,200 tokens at that rate costs 1200 * 0.000003 = 0.0036, i.e., a fraction of a cent β trivial per call, meaningful across millions of calls, which is exactly why the next steps matter.
Applying Per-Million Pricing to Your Prompt
API price lists usually quote a rate per one million tokens (often written "per 1M tokens"). That unit exists because a single token costs a tiny fraction of a cent, so per-token prices would be hard to read. The conversion is simple division.
To get the cost of one request, count the input tokens, divide by one million, and multiply by the rate:
cost_per_request = (input_tokens / 1_000_000) * price_per_million_input_tokens
Two practical notes:
- Keep tokens and price in the same unit. If the rate is quoted per 1M, divide by 1,000,000 β not 1,000. A misplaced zero changes the estimate by a factor of 1,000.
- Apply the rate to the category it belongs to. Most pricing separates input (prompt) tokens from output (completion) tokens, and output is typically priced higher. This step covers input only; output and context overhead are handled in the FAQ and should be added before you commit to a budget.
Worked example, using stated assumptions: a rate of $0.50 per 1M input tokens, and a prompt that tokenizes to 800 input tokens.
cost_per_request = (800 / 1_000_000) * 0.50
= 0.0008 * 0.50
= 0.0004 -> $0.0004 per request
Four hundredths of a cent. That number looks negligible β which is exactly why scaling it up matters.
Scaling Up: Request, Day, Month, and Year Cost Projections
A per-request cost only becomes meaningful when multiplied by volume. The formulas chain directly:
daily_cost = cost_per_request * requests_per_day
monthly_cost = daily_cost * 30
yearly_cost = daily_cost * 365
Using the example above ($0.0004 per request) and assuming 10,000 requests per day:
daily = 0.0004 * 10_000 = $4.00
monthly = 4.00 * 30 = $120.00
yearly = 4.00 * 365 = $1,460.00
(Check: 10,000 Γ 0.0004 = 4; 4 Γ 30 = 120; 4 Γ 365 = 1,460. Correct.)
Notice the leverage: a prompt that grows from 800 to 1,600 tokens doubles every figure in that column. Prompt length and request volume are the two dials that dominate the bill, and both are under your control.
Budgeting checklist:
- Count tokens with the tokenizer that matches your model family, not a character or word estimate.
- Confirm the quoted rate is per 1M, not per 1K.
- Separate input and output rates; estimate output tokens per response.
- Add any fixed context overhead (system prompt, retrieved documents, conversation history) to the input count.
- Multiply by realistic requests/day, then by 30 and 365.
- Re-run the estimate whenever the prompt template or model changes.
One code idea β a small helper that keeps the arithmetic in one place:
def request_cost(input_tokens, price_per_million, output_tokens=0,
output_price_per_million=0.0):
return (input_tokens / 1_000_000) * price_per_million + \
(output_tokens / 1_000_000) * output_price_per_million
def project(cost_per_request, requests_per_day):
daily = cost_per_request * requests_per_day
return {"day": daily, "month": daily * 30, "year": daily * 365}
Treat every result as an estimate: token counts vary with wording, and real traffic fluctuates. Build in a margin rather than budgeting to the exact cent.
Frequently Asked Questions
What is the difference between characters, words, and BPE tokens when estimating cost?
Characters are individual letters or symbols, words are whitespace-separated units, and BPE (byte pair encoding) tokens are the subword chunks a tokenizer actually splits text into β which is what pricing is based on. A rough English rule of thumb is about 4 characters per token, or roughly 0.75 words per token, but these are estimates that drift with text type, punctuation, and formatting. Always count with the tokenizer used by your model rather than converting from character or word counts.
How do I apply a per-million input token price to a single prompt?
Divide the price by one million to get a per-token rate, then multiply by your counted input tokens:
cost_per_request = (price_per_million / 1_000_000) * input_tokens
For example, at an assumed $X per million input tokens and 500 tokens, the single-request cost is (X / 1_000_000) * 500. Treat the price as a variable you plug in from your provider's current schedule; the arithmetic stays the same.
Should I include output tokens and context overhead in my budget estimate?
Yes, for a realistic budget. Output tokens are usually priced higher than input tokens, so estimate them separately with their own per-million rate, and add any fixed context you resend on every call β system prompts, retrieved documents, conversation history, and tool schemas β since those inflate the input count on each request. A single-request estimate that ignores both will understate your bill.
How do I scale a single-request cost to daily, monthly, and yearly totals?
Multiply the per-request cost by your request volume over each period:
daily = cost_per_request * requests_per_day
monthly = daily * 30
yearly = daily * 365
Use 30 and 365 as stated assumptions for calendar scaling, and keep them visible so the projection is auditable. If traffic varies, compute the average requests per day first, then scale from that.
Why does the same text produce different token counts across tokenizers?
Tokenizers differ in their vocabulary, merge rules, and training data, so the same sentence can split into different numbers of subword units β and some handle whitespace, code, or non-English text more efficiently than others. Unicode normalization and special-token handling can also shift the count. This is why you should count tokens with the exact tokenizer paired to your model and re-run the estimate whenever you switch models.