BLACK FRIDAY12/8(火)23:59 まで12/8 まで

文档400 输入太长

400 The request could not be processed(输入太长)

输入超过模型的上下文长度时,Echo Token Station 的 API 返回 HTTP 400 的原因与解决方法。有的模型只返回「The request could not be processed. Please check the request and try again.」,看不出原因是长度。

输入(包括之前的对话和附加的文档)超过模型一次能处理的 token 数(上下文长度)时返回的错误。有的模型返回的文字看不出原因是长度。

错误示例

400invalid_request_error(OpenAI 格式的 error.type),error.code 是 null

下面是给 qwen3-32b 发送约 306,000 字的输入时的响应(OpenAI 格式)。

JSON
{"error":{"message":"The request could not be processed. Please check the request and try again.","type":"invalid_request_error","param":"","code":null}}

其他模型有时会原样返回上游 API 的文字(例:prompt is too long: 250000 tokens > 200000 maximum)。

常见原因

  1. 对话变长了:聊天应用和智能体每次都会把之前的对话一起发送
  2. 把很大的文档或文件内容放进了输入
  3. 工具假定的上下文长度比模型长:Claude Code 会把不认识的模型 ID 的上下文长度当作一个假定值,并把对话发送到这个长度为止

请求正文超过 128 MB 时,返回的是另一个错误(Invalid request: request body exceeds 128 MB: request body too large)。

解决方法

  1. 在模型一览的模型页面确认所用模型的上下文长度
  2. 减少输入:删掉旧的对话、把文档分开发送、只放需要的部分
  3. 换成上下文长度更长的模型
  4. 在 Claude Code 里使用 Claude 以外的模型时,把模型页面上的上下文长度(token 数)填进环境变量 CLAUDE_CODE_MAX_CONTEXT_TOKENS
bash
export CLAUDE_CODE_MAX_CONTEXT_TOKENS="<模型页面上的上下文长度>"

相关页面