How to fix 'maximum context length exceeded'

Every model has a context window: the maximum tokens it can take in one request, counting your instructions, the whole chat history, any files and the answer it is about to write. Go over it and the request fails, or the app silently drops the oldest messages.

Errors and limits · Updated November 25, 2026

What actually fills the window

  • System prompt and company instructions.
  • The full chat history, which is resent on every turn.
  • Pasted text and attached files after extraction. A 40-page PDF is roughly 25,000 to 30,000 tokens.
  • Tool results in agent runs, such as web pages and search results.
  • The space reserved for the answer (max_tokens).

Five fixes, cheapest first

  1. Start a new chat for a new task. Long threads are the most common cause.
  2. Lower max_tokens to what the answer needs, which frees room for input.
  3. Summarize older turns and keep the summary instead of the raw history.
  4. For big document sets, retrieve only the relevant passages (RAG) instead of sending everything.
  5. Switch to a model with a larger window for the jobs that truly need it.

Long-context models with the lowest prices right now

Current models with at least 1 million tokens of context, cheapest first. Bigger windows cost more per request when you fill them, so use them for the jobs that need them.

Cheapest current models with 1M+ token context
ModelContextInput / Output per 1M
Qwen3.7 Flash1M$0.03 / $0.13
DeepSeek V4.1 Flash1.05M$0.051 / $0.20
DeepSeek V4 Flash 04231.05M$0.09 / $0.18
Qwen3.5-Flash1M$0.065 / $0.26
MiniMax M3.1 Flash1.05M$0.075 / $0.30
Llama 4 Scout1.31M$0.10 / $0.30
Gemini 2.5 Flash Lite1.05M$0.10 / $0.40
GPT-4.1 Nano1.05M$0.10 / $0.40

Keep long context affordable

Filling a 1M-token window on every request is expensive even on a cheap model. Shared, reusable context helps: in Intrascope, company and project Manifests hold the background once, and teams pick a long-context model only for the projects that need it.

Frequently asked questions

  • Roughly: 1,000 tokens is about 750 English words, or 1.5 pages. A 128K window holds about 190 pages; a 1M window about 1,500 pages.

  • Yes. Input plus the requested output must fit inside the window, which is why lowering max_tokens can fix the error.

AI for the whole team, with limits that make sense

Intrascope gives every employee approved models, shared company context and budgets per user and team. Your own API keys or managed usage. 7-day free trial, no card.