Skip to content

HTTP 400 maximum context length Codex

Quick fix

Upgrade cc-switch to fix the missing auto_compact_token_limit, or manually set the context window limit in the model catalog json.

Error output
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.

When cc-switch generates the locally routed model_catalog_json, it does not correctly set auto_compact_token_limit and truncation_policy.limit. As a result, Codex or Claude Code cannot know when to trigger automatic context compaction. The context keeps growing until it exceeds the model's maximum context length and causes an HTTP 400 error.

Some users also report that including images in the conversation reliably triggers this issue because models such as DeepSeek-v4 do not support vision. The same context-compaction failure also exists when other models such as GLM-5.1 are connected to Claude Code.

  1. Upgrade cc-switch to a version that includes the PR #5534 fix. This update makes auto_compact_token_limit and truncation_policy.limit dynamically follow the contextWindow setting entered in the CC Switch UI.

  2. If you cannot upgrade yet, manually edit the generated model catalog json file. Explicitly set the context window size and declare the model as non-multimodal to avoid image-related token errors.

    // 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
Why does submitting an image make this error more likely?
Models such as DeepSeek-v4 do not support vision. Submitting images can cause abnormal requests. Use a vision-capable model for image tasks, or explicitly declare the model as non-multimodal in the configuration.
Does this also happen when using GLM-5.1 with Claude Code?
Yes. If cc-switch does not correctly pass auto_compact_token_limit, any model with a limited context can fail to trigger automatic compaction and return an HTTP 400 error in long conversations.

This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.