Skip to content

Lesson 29 ยท Inference and Optimization

Context Windows in ChatGPT and Claude

Understand context windows in ChatGPT and Claude: why app limits differ from API limits, what fills the window, what happens on overflow and how to manage it.

The context window is the amount of text and other input, measured in tokens, that a model can work with at one time, including the response it is writing. The KV cache and serving lessons show why long contexts cost memory and computing work. Now see what this means when you use ChatGPT and Claude.

The key point: a model's API limit and a chat app's limit can be different numbers.

Figures as of December 2026

Through the API, OpenAI's model page lists a 1.05M-token window, with up to 128K output tokens, for GPT-6.2 Astra, GPT-6.2 Sol, GPT-6.1 Terra and GPT-6 Luna. Anthropic documents a 1M-token window for Claude Fable 5.2, Opus 5.5, Sonnet 5.5 and Haiku 5.5, among others. A single Messages API request to a 1M-window Claude model can generate up to 128K output tokens.

For the ChatGPT app, OpenAI's pricing page showed these total windows when we checked:

ChatGPT plan GPT Instant GPT Reasoning
Free 27K Varies
Go 54K 256K
Plus 54K 256K
Pro 128K 400K

The page says that the space for your own input is smaller than these totals, because instructions, memory and other processing share the window. Business and Enterprise plans were not part of that comparison.

For chat on paid Claude plans, Anthropic's help center says most current models, including the four named above, have a 1M window; some earlier models have 500K, and others 200K. We did not confirm a figure for free Claude accounts.

These values change. Check the official pages before a decision depends on them. A bigger number also does not prove better answers.

What fills the window

Inside the window

Instructions System, yours, project
History Earlier turns
Material Files, images, tools
Output Reasoning and reply
1 / 2

All of these share the space. Claude's documentation states that the system prompt, messages, tool results, images, documents and tool definitions count, and so does the generated output, including thinking. OpenAI says that reasoning tokens occupy the context window too. Cached input still takes up space: caching changes price and speed, not size.

Token counts differ between tokenizers. Word-count rules of thumb are rough, especially for code and for many languages. For an API request, use the vendor's token counting feature where available, and the reported usage.

When the window fills up

Behavior depends on the product:

  • Claude API: if the input alone is too long, the request returns an error. On newer models, if generation reaches the window limit, it stops with the stop reason model_context_window_exceeded.
  • OpenAI API: when generation hits the context limit or your output limit, the response is marked incomplete.
  • Claude app: on paid plans with code execution enabled, Claude can summarize earlier messages as a chat nears the limit. In rare cases, such as a very large first message, you can still hit the limit.
  • ChatGPT app: it may report that the context window is full. Starting a new chat with a short handover note is a dependable response.

A summary loses detail. If exact wording matters, such as a figure or a decision, restate it or attach the source again.

Context size is also not the same as a usage limit. A usage limit controls how much you can use a service in a period of time. Long chats tend to use it up faster.

Trim history in your own app

When you manage conversation history yourself, you decide what stays. This example keeps the system text and the newest turns that fit. It counts words as a stand-in for tokens, which a real application should not do.

Python Stand-in: fit history into a budget

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The access requirement is gone because it was old. Simple trimming drops important facts. Better designs keep a short list of pinned decisions, summarize older turns or retrieve relevant ones. Tool conversations also have pairing rules: keep each tool result together with its call, and follow each vendor's rules for returning reasoning or thinking items.

Some current models also check that earlier history has not been edited. OpenAI warns that changing earlier input for GPT-6.2 can cause earlier reasoning items to be dropped. So read the model's documentation before you rewrite history. Both vendors offer platform features for long conversations, often called compaction. Claude documents server-side compaction as a beta feature as of December 2026.

Large does not mean attentive

Anthropic's context window documentation warns that accuracy and recall can degrade as the token count grows. In any system, test long inputs instead of assuming that every detail is used equally well:

  1. Place known facts at the start, middle and end of a long document.
  2. Ask questions that need them, one at a time and in combination.
  3. Record which are found, and compare with a version that sends only relevant sections.

Start a new chat for a new topic. Old, unrelated text takes space and can pull answers in the wrong direction.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. A model lists about a million tokens in the API. What follows for a chat app?

    Apps can set their own windows, which may depend on plan, model and mode.
  2. 2. What does prompt caching change?

    Cached tokens still occupy context.
  3. 3. What is the main weakness of keeping only the newest messages?

    Age does not measure importance.

Summary

  • API windows and app windows can differ; app figures depend on plan, model and mode.
  • Instructions, history, files, tools, reasoning and output share the space.
  • Overflow behavior differs, and summaries lose detail.
  • Keep important facts, measure real tokens and test long-input recall.

Next: Perplexity and Language Metrics

Your progress is saved in this browser. No account needed.