Home › Developer & IT › LLM Token Cost Calculator
LLM Token Cost Calculator
Computes the cost of large-language-model API calls from the number of input, cached-input and output tokens per request, the prices per million tokens supplied by the caller, and the number of requests.
When to use
You are budgeting an LLM feature, comparing providers at their published per-million-token prices, or estimating the monthly bill for a given request volume.
Do not use when: You need token counts from text (tokenizers are model-specific; roughly 4 characters per token in English), or provider-specific extras such as batch discounts, image tokens or fine-tuning fees.
Formula
cost_per_request = (input_tokens − cached_input_tokens) × p_in / 10⁶ + cached_input_tokens × p_cached / 10⁶ + output_tokens × p_out / 10⁶; total_cost = cost_per_request × requests
Pure multiplication with caller-supplied prices in any currency; no price list is built in, so check the provider's current published rates. Cached tokens must not exceed input tokens.
Inputs
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
input_tokens | integer | tokens | yes | Prompt tokens per request, including any cached portion. Range: ≥ 0, ≤ 1000000000 |
output_tokens | integer | tokens | yes | Completion tokens per request. Range: ≥ 0, ≤ 1000000000 |
price_input_per_million | number | per 1M tokens | yes | Price per million uncached input tokens, in your currency. Range: ≥ 0, ≤ 100000 |
price_output_per_million | number | per 1M tokens | yes | Price per million output tokens. Range: ≥ 0, ≤ 100000 |
requests | integer | default 1 | Number of requests (e.g. per month). Range: ≥ 1, ≤ 1000000000000 | |
cached_input_tokens | integer | tokens | default 0 | Part of input_tokens served from a prompt cache and billed at price_cached_per_million. Range: ≥ 0, ≤ 1000000000 |
price_cached_per_million | number | per 1M tokens | default 0 | Price per million cached input tokens (often 10–50 % of the input price). Range: ≥ 0, ≤ 100000 |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
input_cost | number | (input_tokens − cached_input_tokens) × price_input_per_million / 10⁶. | |
cached_cost | number | cached_input_tokens × price_cached_per_million / 10⁶. | |
output_cost | number | output_tokens × price_output_per_million / 10⁶. | |
cost_per_request | number | Sum of the three per-request components. | |
total_cost | number | cost_per_request × requests. | |
cost_per_1000_requests | number | cost_per_request × 1000. | |
tokens_per_request | integer | tokens | input_tokens + output_tokens. |
total_tokens | integer | tokens | tokens_per_request × requests. |
blended_price_per_million | number | per 1M tokens | total_cost / total_tokens × 10⁶: the effective price per million tokens of the mix. |
output_share_percent | number | % | Output cost as a percentage of the cost per request. |
Example
1,000 in / 500 out at 3 and 15 per million, one request: {"input_tokens":1000,"output_tokens":500,"price_input_per_million":3,"price_output_per_million":15,"requests":1} → {"input_cost":0.003,"output_cost":0.0075,"cost_per_request":0.0105,"total_cost":0.01,"tokens_per_request":1500,"output_share_percent":71.43}
Same request 10,000 times: {"input_tokens":1000,"output_tokens":500,"price_input_per_million":3,"price_output_per_million":15,"requests":10000} → {"total_cost":105,"cost_per_1000_requests":10.5,"total_tokens":15000000,"blended_price_per_million":7}
GET https://tttkmbb.com/api/v1/calculate/llm-token-cost?input_tokens=1000&output_tokens=500&price_input_per_million=3&price_output_per_million=15&requests=1
Machine access
- API:
GET https://tttkmbb.com/api/v1/calculate/llm-token-cost(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/llm-token-cost · Markdown: https://tttkmbb.com/developer/llm-token-cost.md · JSON definition: https://tttkmbb.com/developer/llm-token-cost.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="llm-token-cost" - OpenAPI operationId:
calculate_llm_token_cost - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
- OpenAI Help Center – What are tokens and how to count them? (reference)
- Byte pair encoding (Wikipedia) (reference)
FAQ
How do I count tokens?
Use the provider's tokenizer (tiktoken for OpenAI models, the Anthropic token-count endpoint); as a rule of thumb one token is about 4 English characters or ¾ of a word.
How is prompt caching modelled?
cached_input_tokens is the part of each request's prompt billed at the cheaper cached rate; the remainder pays the full input price. Cache-write surcharges are not modelled.
Why are output tokens so much more expensive?
Generation is sequential (one forward pass per token) while prompt tokens are processed in parallel, so providers price output 3–5× higher than input.
Related calculators
- LLM VRAM Calculator — Memory needed to self-host instead of paying per token.
- Percentage Calculator — Percent arithmetic for discounts and shares.
- Reading Time Calculator — Words (≈ tokens × 0.75) to reading time.