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

- Calculator id: `llm-token-cost` · Category: Developer & IT (`developer`) · Tool name: `calculate_llm_token_cost`
- Canonical page: https://tttkmbb.com/developer/llm-token-cost · This document: https://tttkmbb.com/developer/llm-token-cost.md · JSON definition: https://tttkmbb.com/developer/llm-token-cost.json

## Purpose

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.

**Use when:** 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.

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `input_tokens` | integer | tokens | required | Prompt tokens per request, including any cached portion. (min 0, max 1000000000) |
| `output_tokens` | integer | tokens | required | Completion tokens per request. (min 0, max 1000000000) |
| `price_input_per_million` | number | per 1M tokens | required | Price per million uncached input tokens, in your currency. (min 0, max 100000) |
| `price_output_per_million` | number | per 1M tokens | required | Price per million output tokens. (min 0, max 100000) |
| `requests` | integer |  | optional, default 1 | Number of requests (e.g. per month). (min 1, max 1000000000000) |
| `cached_input_tokens` | integer | tokens | optional, default 0 | Part of input_tokens served from a prompt cache and billed at price_cached_per_million. (min 0, max 1000000000) |
| `price_cached_per_million` | number | per 1M tokens | optional, default 0 | Price per million cached input tokens (often 10–50 % of the input price). (min 0, max 100000) |

## Output

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

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

## Data Sources

- OpenAI Help Center – What are tokens and how to count them? — https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them (reference, retrieved 2026-09-24)
- Byte pair encoding (Wikipedia) — https://en.wikipedia.org/wiki/Byte_pair_encoding (reference, retrieved 2026-09-24)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/llm-token-cost?input_tokens=…&output_tokens=…&price_input_per_million=…&price_output_per_million=…`
- `POST https://tttkmbb.com/api/v1/calculate/llm-token-cost` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/llm-token-cost · OpenAPI operationId `calculate_llm_token_cost` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "llm-token-cost", "inputs": {…}}`

## Example

- 1,000 in / 500 out at 3 and 15 per million, one request: inputs `{"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: inputs `{"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
```

## Limitations

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. 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. All values are computed from the formula above; no measurement or live data is involved.

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

- [LLM VRAM Calculator](https://tttkmbb.com/developer/llm-vram-estimate.md) — Memory needed to self-host instead of paying per token.
- [Percentage Calculator](https://tttkmbb.com/math/percentage.md) — Percent arithmetic for discounts and shares.
- [Reading Time Calculator](https://tttkmbb.com/everyday/reading-time.md) — Words (≈ tokens × 0.75) to reading time.
