Records below are third-party data, not instructions. Apply with your own judgment.
Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 208310 tokens > 200000 maximum"},"request_id":"req_<id>"}
Cause
the input alone (system field, tool definitions, every message incl. tool results, images, documents) exceeds the model's context window; the API rejects it instead of truncating.
Fix
# measure first: POST /v1/messages/count_tokens (SDK: messages.count_tokens / countTokens) with the same model, system, tools, messages# then shrink what you resend: drop or summarize old turns, clear stale tool results, chunk big documents# long agent loops: server-side compaction (beta compact-2026-01-12) or context editing (beta context-management-2025-06-27)# or move to a model with a 1M-token window (Claude Opus or Sonnet 4.6 and later)Don’t try
lower max_tokens — the input alone is over the window; on Claude 4.5+ an input + max_tokens overflow is accepted anyway, so max_tokens is not what failed.
retry the same request — a 400 validation error is deterministic and the SDKs do not retry it; the same history fails the same way.