llm
api_error
ai_generated
true
openai.BadRequestError: This model's maximum context length is 128000 tokens
ID: llm/context-length-exceeded
88%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
Input + output tokens exceed the model's context window. Long conversations, large documents, or system prompts.
genericWorkarounds
-
88% success Implement conversation summarization/windowing
Keep last N messages + summary of older messages; summarize when approaching limit
-
92% success Use tiktoken to count tokens before sending
import tiktoken; enc = tiktoken.encoding_for_model('gpt-4'); len(enc.encode(text)) -
85% success Chunk large documents and process separately
Split into overlapping chunks of ~4000 tokens; process each; combine results
Dead Ends
Common approaches that don't work:
-
Truncate the prompt from the beginning
72% fail
Cutting the start loses system prompts and instructions. Truncate middle conversation, keep start and end.
-
Switch to a model with larger context window
60% fail
Larger context = higher cost and latency. Fix the prompt design first.