跳转到内容

HTTP 400 maximum context length Codex

Quick fix

升级 cc-switch 以修复 auto_compact_token_limit 缺失问题,或手动修改 model catalog json 配置上下文窗口限制。

报错原文
CC Switch local proxy failed while handling Codex endpoint /responses. Provider: DeepSeek; model: deepseek-v4-pro; upstream_status: HTTP 400; cause: This model's maximum context length is 1048565 tokens. However, you requested 2786093 tokens (2786093 in the messages, 0 in the completion). Please reduce the length of the messages or completion.

cc-switch 在生成本地路由的 model_catalog_json 时,未正确设置 auto_compact_token_limit 和 truncation_policy.limit。这导致 Codex 或 Claude Code 无法获知何时触发自动上下文压缩,使得上下文只增不减,最终超出模型的最大上下文长度并引发 HTTP 400 错误。

此外,部分用户报告在对话中包含图片时也会必现此问题,因为 DeepSeek-v4 等模型本身不支持视觉功能。该上下文压缩失效问题在 GLM-5.1 等其他模型接入 Claude Code 时同样存在。

  1. 升级 cc-switch 到包含 PR #5534 修复的版本。该更新使 auto_compact_token_limit 和 truncation_policy.limit 能够动态跟随用户在 CC Switch 界面中填写的 contextWindow 设置。

  2. 若暂时无法升级,请手动修改生成的 model catalog json 文件,显式配置 context window 大小,并声明该模型为非多模态以避免图片引发的 token 异常。

    // model_catalog.json
    {
    "contextWindow": 1048565,
    "auto_compact_token_limit": 1000000,
    "truncation_policy": {
    "limit": 1000000
    },
    "multimodal": false
    }
ToolCodex, Claude Code
Version3.16.1 - 3.16.3
PlatformsmacOS
为什么提交图片后更容易出现这个报错?
DeepSeek-v4 等模型不支持视觉功能。提交图片会导致请求异常,建议在处理图片任务时更换其他支持视觉的模型,或在配置中显式声明模型为非多模态。
使用 GLM-5.1 接入 Claude Code 也会遇到这个问题吗?
是的。只要 cc-switch 未正确传递 auto_compact_token_limit,任何上下文有限的模型在长对话中都会因为无法触发自动压缩而报 HTTP 400 错误。

这是一个非官方社区 wiki,与 cc-switch 作者及项目本身无隶属关系。内容整理自项目公开的 GitHub issues。本站不分发任何软件。