← All fixes
anthropic.BadRequestError: prompt is too long (tokens > maximum)
#165Error
anthropic.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'prompt is too long: 215000 tokens > 200000 maximum'}}Why it happens, and why this works
The input (system prompt + messages + tool definitions + tool results) plus room for output is bigger than the model's context window. Agents usually hit it by appending every turn and huge tool outputs forever.
Fix
1. Measure before sending: client.messages.count_tokens(...). 2. Trim history: keep the system prompt and the last N turns, summarize older turns into one message. 3. Truncate tool results (first/last few KB of a log, not the whole file). 4. Lower max_tokens if it plus the input exceeds the window. 5. Use a model with a larger context window if the task truly needs it.
Did it work?
No reports yet0 worked0 didn't
Tried it yourself?
Related fixes
TS1484: 'User' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled
#91error TS1484: 'User' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
typescriptviteVerifiedNo reports yet
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
#84TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
nodeVerifiedNo reports yet
anthropic.RateLimitError: Error code: 429 (rate_limit_error)
#163anthropic.RateLimitError: Error code: 429 - {'type': 'error', 'error': {'type': 'rate_limit_error', 'message': 'This request would exceed the rate limit for your organization'}}