keepcalculator

06 Numbers and Powers

LLM API Tokens: What Counts and How Billing Works

Card No. 06·57630 · Updated · Standard formula, shown below

An LLM API token is a small unit of text—or, in multimodal models, another kind of input or output—that the model processes; it is not necessarily a word. API billing usually multiplies the number of input and output tokens by the model’s separate per-token rates, with some services also charging for tools, images, audio, or other features.

What a token is

Language models process text as token IDs rather than reading whole words as people do. A tokenizer converts text into pieces that the model can handle. A token may be a complete word, part of a word, punctuation, whitespace attached to text, or a short sequence of characters. The exact division depends on the tokenizer and model.

For example, a familiar short word may be one token, while a long or uncommon word can split into several. A sentence’s spaces and punctuation also affect its tokenization. Consequently, counting words or characters does not give an exact token count.

Tokens are also relevant to a model’s context window, the limit on how much material it can process in one request. The request may include instructions, conversation history, retrieved documents, and the latest user message—not just the visible question. The model’s generated answer also uses context capacity.

What counts as input and output

Billing commonly distinguishes input tokens from output tokens. Input is the material sent to the model; output is the material it generates. The provider’s documentation defines precisely which request components fall into each category, and rates may differ substantially between the two.

  • Input: system and developer instructions, user messages, supplied conversation history, and any text or structured content included in the request.
  • Output: the generated completion or response, including tokens returned in formats such as structured data when applicable.
  • Tool use: tool instructions and results can contribute tokens when sent to or returned through the model. A separate tool charge may also apply.
  • Multimodal content: image, audio, or video inputs may be counted using modality-specific rules, rather than a simple text-token estimate.

Some APIs report cached input separately when repeated prompt content qualifies for a caching feature. A provider may apply a different rate to those tokens. Other services may identify categories such as reasoning or audio tokens in usage records. Do not assume every category is billed the same way: check the selected model’s current pricing and usage documentation.

How token billing is calculated

A common basic calculation is:

Request cost = (input tokens ÷ billing unit × input rate) + (output tokens ÷ billing unit × output rate)

The billing unit is often one million tokens, but providers can publish rates in other units. A provider may also add charges for tools or other billable features. The API usage record and the provider’s pricing page are the sources to use for an actual estimate.

For a hypothetical example, suppose a model charges $2 per million input tokens and $8 per million output tokens. A request with 1,500 input tokens and 500 output tokens would have a basic token cost of (1,500 ÷ 1,000,000 × $2) + (500 ÷ 1,000,000 × $8), or $0.007. These rates are illustrative only, not a current offer from a provider.

For repeated requests, sum the token usage by category and apply the corresponding rates. A long conversation may cost more than a short one even if each new user message is brief, because previous messages can be sent again as context. Some products reduce this effect through prompt caching or other mechanisms; eligibility and pricing are model-specific.

Why token counts vary

The tokenizer, language, writing style, and request structure all affect usage. A compact English passage and a passage with unusual names, code, or many symbols can produce different token counts despite similar word counts. Other languages may tokenize less efficiently than English for a particular model. Treat rules such as “one token is about four characters” as rough estimates, not a reliable billing method.

API requests can also contain material that is easy to overlook: role labels or message framing, tool definitions, JSON schemas, and conversation history. Providers may count these details differently or expose only an aggregate usage total. In multimodal APIs, an image or audio clip is not necessarily a fixed number of tokens; its representation and processing method can matter.

Estimating and controlling usage

For a practical estimate, identify the exact model and endpoint, then check how that API reports input, output, cached, and modality-specific usage. A tokenizer supplied for the model can estimate text tokens, but the final API response is better evidence of actual usage, especially when requests contain tools or non-text content.

  • Estimate the full prompt, including instructions and conversation history, rather than only the latest user message.
  • Set an appropriate maximum output length where the API supports it. This limits possible generation, but does not mean the full allowance is automatically billed; billing generally follows usage.
  • Keep only useful conversation history and avoid resending large documents unnecessarily.
  • Use usage fields from API responses or provider dashboards to compare estimates with actual requests.
  • Check whether retries, tool calls, or separate image and audio processing incur additional usage or charges.

Token trimming should not remove instructions or context needed for a correct response. A shorter prompt can reduce input usage, but an overly compressed prompt may lead to worse results or require extra calls.

Tokens, words, and context limits

A token is not a word, and an API’s context limit is not a promise that every token in the limit has the same price. The context window describes how much the model can handle in a request; the price schedule describes what usage costs. Both input and generated output generally consume context capacity, and some model-specific overhead may also count.

Likewise, a maximum output-token setting is a ceiling, not a target. If the model finishes in fewer tokens, usage is normally based on what it actually generated, subject to the provider’s rules. A request can also fail or be truncated if its prompt plus requested output exceeds model limits, so leave room for the answer rather than filling the entire context with input.

Frequently Asked Questions

Is one token the same as one word?
No. A token can be a whole word, part of a word, punctuation, or another text fragment. The tokenizer determines the count.

Are prompt tokens and completion tokens priced the same?
Not necessarily. Many APIs list separate input and output rates, and cached or modality-specific usage may have its own rate. Check the current pricing for the model and endpoint.

Do I pay for the maximum output tokens I set?
Usually the limit is a cap, while charges are based on tokens actually used. Confirm the provider’s billing terms and inspect the usage record for the request.

Does sending a long chat history increase the cost?
It can. If earlier messages are included again in a new request, they may count as input tokens each time, although caching or other model features can change how eligible tokens are billed.

How can I find the exact token count?
Use a tokenizer compatible with the model for an estimate, then consult the API response or usage dashboard for the request’s reported totals. Special content and request formatting can make a rough estimate differ from actual usage.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →