AI Answer Library

How do you estimate the token cost of using a large language model?

Short answer

The formula is: cost per call = (input tokens × input price) + (output tokens × output price), multiplied by calls per day and days. Three things drive it. Input and output are priced separately, and output is usually the more expensive side. Retrieved passages in a RAG prompt and accumulated multi-turn history push input tokens far beyond intuition. And whatever hits the context cache is typically billed at a lower rate. Do not copy anyone's unit prices — vendors adjust them every few months, so use the current official rate card together with token counts you measured yourself.

Key points

  • 01Input and output are priced separately, and output usually costs more. So making the model less verbose is the most direct lever: cap output length, require structured output, strip the pleasantries.
  • 02There is no fixed Chinese-character-to-token ratio. The same text tokenises differently across vendors, so measure a batch of real samples with the target vendor's tokeniser instead of applying a rule-of-thumb coefficient.
  • 03RAG is the main amplifier on a token bill. Every call stuffs several retrieved passages into the context, so input volume can be tens of times the raw question. Lowering top-k and shortening chunks usually saves more than switching models.
  • 04If every turn carries the full history, multi-turn cost grows roughly quadratically with turn count. Summarising or sliding the window is required engineering, not an optional optimisation.
  • 05Context caching materially cuts the cost of a fixed prefix. Putting a long system prompt, stable tool definitions and unchanging knowledge at the very front — byte-for-byte identical across calls — is the precondition for a cache hit.
  • 06For reasoning models, the thinking process is normally billed as output tokens too. Using one for simple classification or extraction can cost noticeably more than expected — route by task difficulty instead.

Token consumption by scenario

The table deliberately omits unit prices: vendors revise rate cards every few months, so any figure written here would go stale and mislead. What it gives instead is the order-of-magnitude relationship and the cost drivers, which are comparatively stable — a plain Q&A call and a long-document extraction call can differ by two orders of magnitude in token count, and their cost levers are entirely different. Find your scenario, identify the dominant variable, then pull the current unit price from the official rate card and put it into the formula.

ScenarioOrder of magnitude per callDominant cost driverWhat to optimise
Single-turn short Q&A, no retrievalHundreds of input tokens, hundreds of outputSystem prompt length and how verbose the output isCompress the system prompt, cap output length, enable context caching
RAG knowledge-base Q&AThousands to tens of thousands of input tokens, hundreds of outputtop-k count × chunk length; the input side dominates completelyLower top-k, rerank so only the best passages are sent, chunk by structure to cut redundancy
Long-document summarisation and contract extractionTens of thousands to over a hundred thousand input tokens, thousands of outputTotal document length, and whether the whole text is re-sent every timePre-filter with rules and send only relevant sections, process in segments then merge, cache the fixed prefix
Multi-turn agent with tool callsTens of thousands cumulatively per task, growing with step countFull history and tool definitions re-sent at every step; retries double itSummarise history, trim tool schemas, cap the step count, fail fast
Batch offline processing: classification and taggingSmall per item, but total = per item × number of itemsItem count, and using a model far stronger than the task needsUse a smaller or local model, use the batch endpoint, filter with rules first where possible

Getting to a budget number you can actually use

Step one: do not guess token counts, measure them. Take 30–50 real requests, run them through the target vendor's tokeniser, and record actual input and output tokens per request, keeping both the mean and the P90 — P90 matters more, because long-tail requests routinely contribute most of the bill. Step two: estimate volume from existing business data — how many cases are handled today, what share will route through AI, and how many model calls one case triggers on average. Step three: apply the formula — monthly cost = (mean input tokens × input price + mean output tokens × output price) × calls per day × 30. Step four: multiply by 1.3 to 1.5 to cover retries, evaluation runs and the waste of a trial period, all of which always appear on a real invoice. Step five: rerun it with P90 instead of the mean and treat that as the budget ceiling. After a month of real traffic, come back and correct the numbers; everything before that is an order-of-magnitude estimate.

Cost levers, ordered by return on effort

One: cut the input. In a RAG setup, dropping top-k from ten to three while adding a reranker usually saves tokens and improves accuracy at the same time — a rare win on both sides. Two: enable context caching. Put the long system prompt and fixed tool definitions at the very front of the prompt and keep them byte-identical; once cached, that portion costs far less, and note that a single changed character invalidates it. Three: route by difficulty. Send simple classification, intent detection and format conversion to a small or local model, and reserve the flagship for requests that genuinely need reasoning — usually the largest saving available and the one most often overlooked. Four: constrain output — require JSON, cap the length, forbid restating the question. Five: trim multi-turn history with a sliding window or periodic summarisation. Six: use batch endpoints for offline work, where many vendors discount non-realtime processing substantially. After the first three, most workloads land at an acceptable bill.

Where this applies

When this answer does not hold

  • This answer deliberately quotes no unit prices. Vendors revise rate cards every few months, so a hard-coded figure would be stale and misleading. Use the current official rate card when you model costs.
  • The Chinese-to-token ratio varies noticeably by tokeniser and no universal coefficient exists. Any "one character equals N tokens" claim holds only for a specific model, so measure with the target vendor's tokeniser.
  • This assumes per-token billing on a hosted API. Self-hosted cost structure is entirely different — hardware depreciation, power and operations staff, with a marginal cost approaching electricity — and this formula does not apply.
  • Caching, batch endpoints and discount schemes differ widely between vendors, and some carry constraints such as a minimum prefix length or a limited cache lifetime. Confirm against your actual call pattern before budgeting on a generic description.

People also ask

  • How is token billing actually calculated?
  • Roughly how many tokens does one LLM call consume?
  • How many tokens is one Chinese character?
  • How do you bring down LLM API costs?
  • How much does RAG increase token cost?
Written by: YGG Technology Solutions TeamPublished: 2026-08-01Last reviewed: 2026-08-01