Skip to content

How an Application Talks to a Language Model: Tokens, Context Windows, and Why Answers Vary

What actually happens when an application calls a language model: one request and one response, tokens as the unit of limits and billing, the context window as a single budget, and why the same question can get a different answer. Explained without code, from the official documentation of OpenAI, Anthropic and Google and recent research.

Isometric illustration of a laptop running an application, sending a row of small coloured tiles along a path to a glowing cube-shaped model; a translucent frame encloses part of the row, and three differently shaped speech bubbles travel back to the laptop

Three Complaints with One Cause

Teams that add an AI feature to their application tend to report the same three surprises within the first few months.

The first is inconsistency. A question that got an excellent answer during the demo gets a weaker, or simply different, answer a week later. The second is cost. The monthly bill from the model provider rises even though the number of users has not. The third is forgetfulness. A long document is uploaded, and the answer ignores a clause that is clearly in it, or a long chat loses track of something the user said at the start.

None of these is a bug in the usual sense. All three follow from how an application and a language model exchange information. Once that exchange is understood, the surprises become design decisions that can be made on purpose.

This article explains the exchange for business owners, campus system managers and IT teams. It covers four ideas: the request and the response, tokens, the context window, and why answers vary. There is no code. The facts come from the official documentation of OpenAI, Anthropic and Google, and from recent research where the documentation is silent.

One Request, One Response

When an application uses a hosted language model, it does not hold a running conversation with it. It sends a request over the internet and receives a response, much like any other web API.

A request typically contains:

  • System instructions: the standing rules for the feature, such as "answer only questions about the academic calendar, in formal Indonesian".
  • Messages: what the user wrote and, in a chat, the earlier turns of the conversation.
  • Supporting material: documents, records from the database or search results that the application wants the model to use.
  • Tool definitions, when the model is allowed to ask the application to look something up or perform an action.
  • Settings: which model to use, the maximum length of the answer and, on some models, how much randomness to allow.

The response contains the generated text, a reason why generation stopped (the answer was complete, or it hit the length limit) and a count of how much was used.

The model does not remember

The model keeps nothing between requests. Anthropic's documentation states it plainly: by default the Messages API is stateless, so the application sends the full conversation history with each request. What looks like memory in a chatbot is the application sending the earlier turns again, every time.

Some providers offer to keep the history on their side, and Anthropic has a similar feature in beta. OpenAI's Responses API, for example, can chain a new request to a previous one, but its conversation state guide notes that the earlier input is still billed as input on every turn. Storing history on the provider's side saves the application from resending it. It does not make the history free.

This has a direct consequence for cost. In a chat, the tenth message carries the nine before it. Each turn costs more than the previous one, even when the user types a single short sentence.

Tokens: The Unit of Limits and Billing

Language models do not read characters or words. They read tokens: pieces of text produced by a tokenizer. A token can be a whole word, part of a word, a single character or a punctuation mark.

Providers publish a rough rule for English. OpenAI's help article on understanding tokens puts it at about four characters per token, or roughly 75 words per 100 tokens, and stresses that this is an estimate. Google's Gemini documentation gives a similar figure.

Tokens matter to an application owner for two reasons:

  1. Billing. Providers charge per token, with separate rates for input (everything sent) and output (everything generated). The rates are on each provider's pricing page and change over time.
  2. Limits. The size of a request and the length of an answer are both measured in tokens.

Language changes the count. Tokenizers are built mostly from English text, so the same sentence in another language usually splits into more tokens. Petrov et al., in a NeurIPS 2023 paper, found that translations of the same text can differ in token count by up to about fifteen times between languages. For an application serving Indonesian users, the English rule of thumb is a lower bound, not an estimate. The way to know is to measure: every response reports the tokens it used, and the major providers offer an endpoint that counts the tokens of a request before it is sent.

The Context Window: One Budget for Everything

The context window is the maximum number of tokens a model can work with in a single request. Anthropic's documentation on context windows lists what counts toward it: the system instructions, every message including documents and tool results, the tool definitions, and the output the model generates.

That last item is easy to miss. The context window is not only how much can be sent. It is one budget shared by the question, everything attached to it and the answer.

Window sizes differ by model and have grown quickly. At the time of writing, Anthropic lists current Claude models at either 200,000 or 1 million tokens, and a single request to its 1-million-token models can generate up to 128,000 output tokens. Specific numbers are worth checking on the provider's model page at the time of building, because they change with each model generation.

What happens at the limit

Two limits apply, and they fail in different ways.

  • The input is too large. If the request alone exceeds the window, the provider rejects it with an error. The application gets no answer at all, so it needs a plan: trim older turns, summarise them, or send fewer documents.
  • The answer is too long. Every request sets a maximum number of output tokens. When the model reaches it, generation stops mid-sentence and the response reports that the limit was the reason. An application that does not check that reason will show users a truncated answer as if it were complete.

Bigger is not automatically better

A large window makes it tempting to send everything: the whole handbook, the full chat history, every record that might be relevant. Research suggests caution.

Liu et al., in "Lost in the Middle" (Transactions of the ACL, 2024), found that models answered best when the relevant information sat at the beginning or the end of a long input, and noticeably worse when it sat in the middle, including models built for long contexts. A 2025 technical report from Chroma, "Context Rot", tested 18 models and reached a similar conclusion: models do not use their context uniformly, and their performance becomes increasingly unreliable as the input grows, even on simple tasks.

The practical lesson is that a context window is a ceiling, not a target. Sending the few passages that answer the question usually works better, and costs less, than sending the whole library. That is the idea behind retrieval-augmented generation, which a later article in this series covers.

Why the Same Question Gets Different Answers

A language model generates text one token at a time. At each step it calculates how likely every possible next token is, then picks one. If it always picked the single most likely token, it would be predictable but often flat and repetitive. So by default it samples: it picks according to the probabilities, which means a less likely token is sometimes chosen, and the rest of the answer follows from that choice.

Temperature is the setting that controls how adventurous that choice is. Lower values concentrate on the most likely tokens; higher values spread the choice wider. A related setting, top-p, limits the choice to the most likely tokens whose probabilities add up to a given share.

Temperature zero is not a guarantee

It is natural to assume that setting temperature to zero makes the output fixed. The providers say otherwise. OpenAI introduced a seed setting for repeatable sampling, and its cookbook describes the result as "mostly" consistent: the system makes a best effort to sample deterministically, and determinism is not guaranteed. Even when the seed, the settings and the identifier of the server configuration all match, the cookbook notes a small chance that responses differ.

Part of the reason lies in the servers, not the model. Providers process many users' requests together in batches, and the size of a batch depends on how busy the service is at that moment. A September 2025 study by Thinking Machines Lab showed that the calculations behind a model can give slightly different results depending on that batch size. In their experiment, one open-weight model was asked the same question 1,000 times at temperature zero and produced 80 different completions. The authors also showed that the effect can be removed with specially written server code, at some cost in speed. For an application calling a hosted API, though, the server load is outside its control.

Sometimes the setting is not there at all

The newest models are moving away from these controls. Anthropic's Messages API guide states that temperature, top-p and top-k are not supported on Claude 4.7 and later models: sending a non-default value returns an error, and from API version 2026-10-21 sending them at all does. The guide's advice is to omit them and guide the model's behaviour through the instructions instead. Teams that planned to make answers consistent by turning a setting down may find the setting is not available.

Other sources of variation

Randomness in sampling is only one cause. Answers also change when:

  • the model changes. Providers update and retire models. A feature pointed at a general model name may quietly move to a newer version.
  • the instructions change. A small edit to the system instructions can shift answers across the whole feature.
  • the context changes. If the application retrieves documents for each question, a newly added document, or a different order of documents, changes what the model sees.

The conclusion for anyone building an AI feature is that variation is a property to design around, not a defect to switch off.

What This Means for an Application Owner

These mechanics turn into a short list of decisions. We recommend making each of them deliberately, before the feature reaches users.

  1. Pin the model version. Use the provider's dated or versioned model identifier rather than a general alias, and record the model version with every request in the application log. When answers change, the log shows whether the model did.
  2. Measure tokens from day one. Store the input and output token counts that every response reports, per feature and per user. Cost questions are then answered from data rather than from the monthly invoice.
  3. Set an output limit and check the stop reason. Choose a maximum answer length that fits the feature, and treat a response that stopped at the limit as incomplete.
  4. Budget the context window. Decide how much of it goes to instructions, history, documents and the answer. Decide what happens to long conversations: trim, summarise or start fresh.
  5. Send what is relevant, not everything. Fewer, better-chosen passages improve answers and lower cost.
  6. Validate output the application depends on. When the answer feeds a form, a database or another system, ask for a structured format and check it before using it.
  7. Keep a set of test questions. A fixed list of real questions with acceptable answers, run whenever the model, the instructions or the documents change, shows whether quality moved.
  8. Put a person in the loop where stakes are high. Decisions about grades, payments or eligibility should be proposed by the model and confirmed by a person.
  9. Do not promise identical answers. Users should hear that the feature gives consistent quality, and the test set is how that promise is kept.
  10. Plan for model retirement. Models are deprecated on a published schedule. Budget time to test and move to a successor, the same way the rest of the stack is kept up to date.

Summary

An application talks to a language model through stateless requests. Everything the model knows about the conversation is sent again each time, measured in tokens, and limited by a context window that the answer shares. The model picks each token by sampling, and even with randomness turned down, server-side details, model updates and changes in context mean answers can vary.

None of this makes language models unsuitable for business or campus systems. It means an AI feature needs the same discipline as any other integration: versions pinned, usage measured, limits handled and output checked. The next articles in this series build on these ideas, starting with how a model can answer from an organisation's own documents.

If you are planning an AI feature and want to work out its token budget, context design and testing before building, get in touch.

References