keepcalculator

06 Numbers and Powers

LLM API Cost Estimates: Count Tokens and Compare Models

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

LLM API cost estimates count the input and output tokens a request uses, then multiply each token total by the selected model’s current per-token rate. Comparing models is useful, but an estimate is only as reliable as its token counts, pricing data, and assumptions about repeated prompts, tools, and other billable features.

What an API cost estimate measures

An estimate projects usage charges for a prompt, a request, or a workload. It generally separates input tokens—the text and other supported content sent to the service—from output tokens generated in response. Many providers publish separate rates for these categories, so combining them into one token total can produce a misleading result.

A basic text-only calculation is:

Estimated cost = (input tokens ÷ 1,000,000 × input price per million) + (output tokens ÷ 1,000,000 × output price per million)

The “per million” unit is common, but published rates may use another unit. Match the calculator’s unit to the provider’s price table. This arithmetic estimates usage charges; it does not guarantee the final invoice or include charges that are outside the stated rates.

How token counting works

Tokens are pieces of text processed by a model, not a fixed number of words or characters. A token may be a whole word, part of a word, punctuation, or a spacing pattern. Tokenization depends on the model’s tokenizer, so the same sentence can yield different token counts with different models. Code, uncommon names, and some languages can also tokenize differently from ordinary English prose.

For a rough illustration, suppose a request contains 1,200 input tokens and produces 300 output tokens. If a model’s listed rates are P input dollars and Q output dollars per million tokens, its estimated cost is 0.0012P + 0.0003Q dollars. This example shows the calculation without assuming a provider’s current rates; prices can change, so check the applicable pricing page before relying on a result.

When available, use the provider’s tokenizer or an estimator designed for the specific model. A generic word-count conversion can help with an early rough budget, but it is not a dependable substitute for tokenization. The exact usage reported by the API response is usually more useful for checking a completed request.

Comparing models fairly

For a first-pass comparison, calculate each model’s input and output costs separately using the same workload assumptions. Then consider whether the models can actually perform the task to the required standard. A lower rate per token does not necessarily mean a cheaper result if that model needs longer prompts, produces more text, or requires retries.

  • Hold the workload constant: use the same estimated input and output volumes for each candidate.
  • Check model-specific rates: verify the exact model and the relevant input, output, and any discounted or special categories.
  • Account for quality and task fit: compare outcomes on representative examples, not price alone.
  • Include operational usage: consider retries, multi-step workflows, and tool calls where they incur charges.
  • Compare cost per useful result: a response that meets the requirement may be more meaningful than cost per request.

Some pricing schedules distinguish cached input, batch processing, or other request types. Those categories may have different conditions and rates. Apply a discounted rate only to tokens that qualify under the provider’s rules; do not assume every repeated phrase or request receives a discount.

Estimating a workload, not just one request

For a recurring workload, multiply the expected request volume by the average cost per request, while allowing for variation. If 10,000 requests each averaged 1,200 input tokens and 300 output tokens, the workload would total 12 million input tokens and 3 million output tokens. Apply the relevant rates to those totals, or multiply the single-request estimate by 10,000 if the assumptions are identical.

Real usage often varies. Short questions and long documents may have very different prompt sizes, and generated answers can vary in length. A better projection uses samples that represent the actual mix of requests. Track typical and high-usage cases separately when a small number of long interactions could materially change the total.

For a production estimate, make the assumptions explicit: requests per day or month, average input and output tokens, model mix, eligible cached usage, and expected retries. Recalculate when prompts, response limits, models, or provider rates change.

What token estimates can miss

A plain text count may not capture every billable component. Depending on the API and feature used, requests can involve image, audio, video, tool, or other structured inputs, and the provider may measure or price them differently. Conversation history also matters: if an application sends previous messages again on each turn, those tokens may be counted again as input.

Other common sources of a gap between an estimate and reported usage include:

  • System instructions, formatting rules, and metadata added by the application.
  • Tool definitions or structured outputs that add to the request.
  • Different model tokenizers or pricing tiers than the estimate assumed.
  • Retries, multiple model calls, or agent steps within one user-visible task.
  • Minimums, rounding, or feature-specific billing rules stated by the provider.

Do not infer that every API call is billed only by the visible text in a chat box. Check the provider’s documentation for how it reports usage and prices non-text features, and compare estimates with actual usage records for representative calls.

Common mistakes and practical checks

The most frequent arithmetic error is mixing units—for example, multiplying a token count by a rate quoted per million without dividing the count by one million. Another is treating input and output as equally priced when the schedule lists different rates. Make sure the price applies to the exact model and request category, and keep currency and billing units consistent.

Before using an estimate to plan a budget, check these points:

  • Is the token count from the correct model’s tokenizer or an appropriate estimate?
  • Does the input total include system prompts, conversation history, and tool schemas?
  • Are output tokens estimated realistically, rather than assumed to equal input tokens?
  • Are rates current and tied to the correct model, modality, and service category?
  • Have you compared the estimate with actual usage from a small representative sample?

Estimates are planning tools, not guarantees. The provider’s usage records and billing terms determine how a particular service accounts for requests. Where cost control matters, set practical output limits and monitor usage, while ensuring those limits do not prevent the application from completing its task.

Frequently Asked Questions

Do LLM APIs charge for input and output tokens separately?
Many publish separate input and output rates, but exact pricing depends on the provider, model, and request type. Check the current rate schedule rather than assuming one combined price.

How accurate are online token counters?
A counter that supports the exact model can give a useful count for supported text. Generic counters may differ, and multimodal content or API-added fields can make a simple text count incomplete.

Are tokens the same as words?
No. Tokens are units used by a model’s tokenizer and may represent whole words, word fragments, punctuation, or other text patterns. There is no universal words-to-tokens conversion that works exactly for every model and text.

Why did my actual API cost exceed the estimate?
Possible reasons include longer prompts or responses, repeated conversation history, retries, extra model calls, non-text features, or an incorrect rate assumption. Compare the API’s reported usage with the estimate’s inputs.

Can I compare two models using price per million tokens?
That is a useful starting point, not a complete comparison. Use the same representative workload, account for separate input and output rates, and consider whether each model meets the task’s quality and reliability needs.

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 →