All fixes · Any provider · 400 · Model limits

“Maximum context length exceeded” (400): What It Means and How to Fix

This model's maximum context length is N tokens

The request's input tokens plus the output it asks for (max_tokens) are larger than the model's context window, so the API rejects it with a 400 before generating anything; trim or summarize the input, lower max_tokens, or switch to a longer-context model. It’s a hard model limit, not a billing or rate issue.

What causes it

  • Long conversation history resent in full every request.
  • Stuffing whole files, docs, or codebases into the prompt.
  • max_tokens set so high that input + output exceeds the window.

How to fix it

  1. Trim the prompt and lower max_tokens so input + output fits the window.
  2. Summarize or truncate old messages instead of resending everything.
  3. Chunk large documents and retrieve only the relevant parts (RAG).
  4. Use a model with a larger context window for genuinely large inputs.

Running an agent? Coding and research agents trip this constantly by re-sending big contexts each step. Compacting the session in the agent and a large-context model both help.

Keep working on a fixed monthly plan

Standard Compute serves large-context frontier models, so you can pin a model with a bigger window when a session outgrows a small one.

Plans from $19 a month with $19 of compute. Eligible new accounts can try $0.25 of compute first, no card. Trial terms

FAQ

Does context length include the response?

Yes. The window covers input tokens plus the tokens the model generates. If max_tokens is large, your input has to be proportionally smaller.

Related errors