HomeDeveloper & 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

ParameterTypeUnitRequiredDescription
input_tokensintegertokensyesPrompt tokens per request, including any cached portion. Range: ≥ 0, ≤ 1000000000
output_tokensintegertokensyesCompletion tokens per request. Range: ≥ 0, ≤ 1000000000
price_input_per_millionnumberper 1M tokensyesPrice per million uncached input tokens, in your currency. Range: ≥ 0, ≤ 100000
price_output_per_millionnumberper 1M tokensyesPrice per million output tokens. Range: ≥ 0, ≤ 100000
requestsintegerdefault 1Number of requests (e.g. per month). Range: ≥ 1, ≤ 1000000000000
cached_input_tokensintegertokensdefault 0Part of input_tokens served from a prompt cache and billed at price_cached_per_million. Range: ≥ 0, ≤ 1000000000
price_cached_per_millionnumberper 1M tokensdefault 0Price per million cached input tokens (often 10–50 % of the input price). Range: ≥ 0, ≤ 100000

Outputs

OutputTypeUnitDescription
input_costnumber(input_tokens − cached_input_tokens) × price_input_per_million / 10⁶.
cached_costnumbercached_input_tokens × price_cached_per_million / 10⁶.
output_costnumberoutput_tokens × price_output_per_million / 10⁶.
cost_per_requestnumberSum of the three per-request components.
total_costnumbercost_per_request × requests.
cost_per_1000_requestsnumbercost_per_request × 1000.
tokens_per_requestintegertokensinput_tokens + output_tokens.
total_tokensintegertokenstokens_per_request × requests.
blended_price_per_millionnumberper 1M tokenstotal_cost / total_tokens × 10⁶: the effective price per million tokens of the mix.
output_share_percentnumber%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

Sources

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