This model's maximum context length is exceeded (context_length_exceeded)
- OpenAI
- AI APIs
What it means
The request sent more text than the AI model can read at once. In chat features it usually grows over time, as every message adds to the history sent with the next one.
Why it happens
- The whole conversation history is sent with every message.
- Large documents or database rows are pasted into the prompt.
- A smaller model was swapped in with a smaller limit.
How to fix it
- Send only the recent messages, and summarise older ones.
- Send the relevant parts of documents, not whole files.
- Count tokens before sending and cut to fit.
- Smaller prompts also cost less: check with the AI bill calculator.
Let your AI find the cause
Paste this into Claude Code, Cursor, Lovable or whichever AI built your app. It looks first and changes nothing until you have read the answer.
My AI feature fails with 'maximum context length' / context_length_exceeded. Without changing anything yet, show me what goes into each AI request (system prompt, history, documents), roughly how many tokens each part is, and which part grows over time.