Tokens, context windows, and cost

Last updated

If you use AI through an API, or look closely at the limits of a chat plan, you will quickly run into three related ideas: tokens, context windows, and cost. They explain why long documents sometimes get cut off, why a model forgets the start of a long conversation, and why some requests cost far more than others.

What a token is

Models do not read text as whole words or individual letters. They break text into small chunks called tokens. A token might be a whole common word, part of a longer word, a punctuation mark, or a space plus a word.

As a rough rule of thumb for English text, one token is about three-quarters of a word, so 100 tokens is roughly 75 words. The exact ratio depends on the model's tokenizer and the type of text. Code, numbers, unusual words, and many non-English languages often use more tokens per word.

Images, audio, and files are also converted into tokens or token-equivalents when sent to multimodal models, and they can use a surprising number.

Why it matters: almost everything about model limits and pricing is measured in tokens, not words or pages.

Input tokens and output tokens

Every request has two sides:

  • Input tokens are everything the model reads: your prompt, any documents you include, the system instructions the app adds, and in a chat, the earlier conversation history.
  • Output tokens are everything the model writes back.

Most providers price these separately, and output tokens usually cost more per token than input tokens. Reasoning models may also generate internal "thinking" tokens before the visible answer, and these are typically billed as output even if you do not see all of them.

What a context window is

The context window is the maximum number of tokens a model can consider in a single request, including both input and output. Think of it as the model's working memory for that request.

Context windows have grown dramatically. Some models handle a few thousand tokens; many current models handle hundreds of thousands, and some advertise even more. A large context window lets you include long documents, big codebases, or extended conversation histories.

A few important points:

  • The model has no memory between requests by default. A chat app creates the feeling of memory by resending the conversation history with each new message. That history counts against the context window and the cost every time.
  • When a conversation exceeds the window, the app must drop or summarize older parts. That is why very long chats can seem to forget early instructions.
  • Bigger is not always better in practice. Models can pay less attention to details buried in the middle of very long inputs, and processing long inputs costs more and takes longer. Relevant context beats maximum context.

How AI usage is priced

Pricing varies widely by provider and model, and it changes often, so check current rates on the provider's pricing page. The common patterns are:

Pay per token through an API

API access is usually billed per million tokens, with separate rates for input and output. Larger, more capable models cost more per token than smaller ones, sometimes by a large multiple. Some providers offer discounts for cached input that repeats across requests, or for batch jobs that do not need an immediate answer.

Subscriptions for chat apps

Consumer and business chat plans usually charge a flat monthly fee per user, with usage limits that may be expressed as messages, time windows, or access to certain models. The token math still exists behind the scenes, but it is hidden.

Self-hosted models

If you run an open-weight model on your own hardware, there is no per-token fee. Instead you pay for hardware, electricity, and the time to maintain it. See Local AI vs hosted APIs vs private cloud.

What drives the cost of a request

For API usage, the main factors are:

  1. Model choice. This is usually the biggest lever. A small model may cost a tiny fraction of a flagship model for the same request.
  2. Input length. Long prompts, large documents, and long conversation histories add input tokens to every request.
  3. Output length. Long answers cost more, and output is usually priced higher than input.
  4. Reasoning effort. Reasoning models can generate many internal tokens on hard problems.
  5. Volume. A cheap request repeated thousands of times a day adds up.
  6. Tools. Web search and other tools may carry their own fees, and their results add input tokens.

Practical ways to control cost

  • Use the smallest model that does the job well. Test a smaller model before defaulting to the largest. See Selecting the right model.
  • Trim the input. Send the relevant sections of a document, not the whole archive. Retrieval systems do this automatically. See Retrieval-augmented generation (RAG) explained.
  • Ask for concise output when you do not need length.
  • Start new conversations instead of carrying long histories forward when the earlier context is no longer needed.
  • Use caching and batch options where your provider offers them.
  • Set spending limits and monitor usage. Most API providers offer usage dashboards and budget alerts. Teams that share access often add per-user or per-project limits, either through provider settings or a gateway that sits in front of several providers.
  • Route by task. Sending simple requests to cheaper models and hard requests to stronger models can reduce cost without hurting quality. See How routers add intelligence to the intelligence.

A simple way to estimate

To get a rough estimate for a recurring task:

  1. Estimate the average words in and out per request, and convert to tokens (words divided by 0.75 is a reasonable rough figure for English).
  2. Multiply by the provider's current per-token rates for input and output.
  3. Multiply by the expected number of requests per month.
  4. Add a margin for retries, longer-than-expected inputs, and growth.

Then run a small pilot and compare your estimate against actual usage in the provider's dashboard. Real numbers are always better than estimates.

Key takeaways

  • Tokens are the units models read and write; in English, a token is roughly three-quarters of a word.
  • The context window is the maximum tokens a model can handle in one request, including conversation history.
  • Models do not remember between requests; apps resend history, which costs tokens.
  • API cost depends mostly on model choice, input length, output length, and volume.
  • Use the smallest capable model, send only relevant context, and monitor usage with limits in place.