Cost per Token

Topics Covered

What a Token Costs

Two kinds of tokens

The basic formula

Throughput is the denominator

Utilization is the hidden multiplier

Cost per request

Hidden token costs

Why the price gap exists

Context length raises cost

A worked request example

Cost per useful outcome

Tokens differ across models

Embeddings and other model calls

Every LLM product eventually faces the question of what each response costs and whether the business can afford it at scale. The answer comes down to cost per token, which depends on hardware prices, throughput, utilization and the mix of input and output tokens. This lesson builds the cost model from first principles, compares self hosting with API pricing, walks through the levers that lower cost, and connects token costs to the unit economics of a product.

Two kinds of tokens

Input tokens and output tokens cost different amounts. Input tokens are processed in parallel during prefill, which is compute bound and efficient: the GPU handles thousands of them in one pass. Output tokens are generated one at a time during decode, which is memory bound: each step reads the model weights and KV cache to produce a single token per sequence. As a result, output tokens cost more per token to produce, often three to five times more. API price lists reflect this, typically charging several times more per output token than per input token.

Input tokens go through together in one pass. Output tokens come one at a time. That is why output tokens cost more.

The basic formula

For self hosted serving, the cost per token is the cost of the hardware per unit time divided by the tokens it produces in that time. If a deployment costs a certain amount per hour and produces a certain number of tokens per hour, dividing gives the cost per token. Multiplying by one million gives cost per million tokens, the unit most price lists use. This simple ratio hides the hard part, which is knowing the real tokens per hour under production conditions, including idle time, uneven load and the mix of request shapes.

Throughput is the denominator

The denominator, tokens per hour, depends on the model, the hardware, the engine, the batch size and the request shapes. A well tuned deployment with large batches can produce thousands of output tokens per second per GPU for a small model, while a large model on the same GPU may manage a few hundred. Batch size matters most: decode throughput rises almost linearly with batch size until compute or memory limits are reached, which is why continuous batching and efficient KV cache management lower cost so much.

Utilization is the hidden multiplier

Hardware costs money whether or not it is busy. A deployment that could produce one thousand tokens per second at full load, but averages three hundred because traffic is uneven, has an effective cost per token more than three times higher than its peak throughput suggests. Utilization, the fraction of capacity actually used, is often the largest single factor in real cost. Many self hosted deployments run at twenty to forty percent average utilization because they are sized for peaks, which is why autoscaling, batching background work into quiet periods and sharing capacity across workloads matter.

The GPU bill is the same every hour. When traffic is low, fewer tokens share that bill, so each token costs more.

Cost per request

Products think in requests, not tokens. Cost per request is the input tokens times the input price plus the output tokens times the output price, plus any overhead such as retries, tool calls or multiple model calls in an agent loop. A chat request with two thousand input tokens and five hundred output tokens has a very different cost from a summarization request with fifty thousand input tokens and three hundred output tokens. Understanding the token profile of each feature is the first step in managing cost, and it often reveals that a few features dominate the bill.

Hidden token costs

Several sources of tokens are easy to miss. System prompts repeated on every request add input tokens. Conversation history grows with every turn, so long chats resend large contexts. Retrieval augmentation adds documents to the prompt. Agents make many model calls per task, each with growing context. Reasoning models generate hidden thinking tokens that are billed as output. Retries after errors or failed validation double the cost of those requests. Measuring actual tokens per request in production, broken down by source, often reveals that hidden tokens exceed the visible ones.

Why the price gap exists

The gap between input and output prices follows from how GPUs spend their time. In prefill, a single forward pass multiplies the weights against thousands of input positions at once, so each weight read from memory does a lot of useful arithmetic. In decode, each forward pass produces one token per sequence, so the same weights are read for far less work. Batching many sequences together narrows the gap by sharing each weight read across sequences, but the KV cache read grows with every sequence and every token of context, so decode never becomes as efficient as prefill. The price list is a compressed summary of that hardware reality.

Context length raises cost

Longer contexts cost more in two ways. They add input tokens, which are billed directly. They also make every decode step more expensive, because attention reads the whole KV cache for each new token. A request with a hundred thousand tokens of context produces output tokens much more slowly, and occupies far more KV cache memory, than a request with two thousand. Some providers charge higher rates above a context threshold for this reason. For self hosted serving, long contexts reduce the number of sequences that fit in a batch, which lowers throughput and raises the cost of every token on the deployment.

Each new token reads the whole cached context. A longer context means more reading per token, and a higher cost.

A worked request example

Take a support chat request with a 1,500 token system prompt, 3,000 tokens of conversation history, 2,000 tokens of retrieved articles, a 100 token user message and a 400 token reply. That is 6,600 input tokens and 400 output tokens. At an API price of 3 dollars per million input tokens and 15 dollars per million output tokens, the input costs about 2 cents and the output about 0.6 cents, roughly 2.6 cents per request. Notice that input dominates even though output is five times more expensive per token, because there is so much more of it. Caching the system prompt and trimming history would cut this request cost substantially.

Cost per useful outcome

Cost per request is not the whole story. What matters to the business is cost per useful outcome: a resolved support ticket, an accepted code suggestion, a completed document. If a cheaper model needs three attempts to produce an acceptable answer while an expensive model succeeds the first time, the expensive model may be cheaper per outcome. Measuring success rates alongside cost per request gives cost per outcome, which is the number that should guide model and prompt choices.

Tokens differ across models

Different models use different tokenizers, so the same text becomes a different number of tokens. A tokenizer optimized for English might turn a paragraph into a hundred tokens, while another produces a hundred and thirty. Non English text and code often vary even more. Comparing prices per million tokens across models without accounting for this can mislead; comparing cost per request on real samples is more reliable. When switching models, re measuring token counts avoids surprises in the bill.

Embeddings and other model calls

LLM products often include other model calls: embedding models for retrieval, rerankers, moderation classifiers and speech models. These are usually much cheaper per token than generation, but at high volume they add up, especially embeddings for large document collections that are re embedded when the model changes. Including them in the cost model gives a complete picture and sometimes reveals that a retrieval pipeline or moderation step costs more than expected.

Count tokens where they come from

Break each request into system prompt, history, retrieved context, user input, reasoning and visible output. The biggest savings usually hide in the parts nobody looks at.