Skip to content

unexpected status 401 Unauthorized: Codex using Kimi

Quick fix

In Codex config.toml, set the AUTO COMPACT threshold below Kimi's 256K limit, verify model mapping, and reduce unnecessary MCP usage.

Error output
unexpected status 401 Unauthorized: CC Switch local proxy failed while handling Codex endpoint /responses. Provider: Kimi; model: kimi-k2.7-code; upstream_status: HTTP 401; cause: k3-256k supports only 256K context., url: http://127.0.0.1:15721/v1/responses

Kimi's k3-256k permits only a 256K context, while Codex's automatic compaction threshold for its default 272K context is about 258K. The request may exceed Kimi's input limit before Codex triggers automatic compaction, causing the upstream service to return HTTP 401 first and compaction to fail.

Another variant occurs while the Codex UI still shows 23% or 28% remaining. The UI figure may not fully include the system/developer prompt, tool definitions, MCP schema, reasoning fields, or reconstructed history. Kimi may also classify a model alias as the 1M context tier. Neither issue provides a verified AUTO COMPACT field name or exact value.

  1. Adjust the AUTO COMPACT fields in Codex config.toml so the compaction threshold is clearly below Kimi k3-256k's 256K input limit. The issue does not provide a confirmed field name or exact value.

  2. Start a new empty session and test with the same model. If an empty session works but a long session fails, the actual request body, tool schema, or reconstructed history is triggering the upstream limit.

  3. Temporarily disable unnecessary MCP tools to reduce the tool definitions and schema sent with each request.

  4. Check the model field and upstream response body in the CC Switch proxy logs. Confirm that the final model name is the 256K tier of regular k3 or k3-coding, not an alias recognized as 1M context.

ToolCodex
Version受影响版本:3.18.0
PlatformsWindows
Why does Codex show only 23% of the context used or 28% remaining while Kimi reports that 256K was exceeded?
The visible context estimate in the Codex UI may not fully include the system/developer prompt, tool definitions, MCP schema, reasoning fields, and reconstructed history, so the actual upstream request may be larger. A model alias may also be recognized as the 1M context tier.
Does CC Switch call the model itself to compact the context after receiving /responses/compact?
The issue reports that CC Switch sends the /responses/compact content to /chat/completions, which has no compact capability. If the input already exceeds Kimi's 256K limit, the upstream service returns an error first. The current discussion recommends using Codex's AUTO COMPACT fields to trigger compaction earlier.
What should I do if the issue persists after reducing MCP usage?
Check the actual model field and upstream response body in the CC Switch proxy logs, and confirm that model mapping did not select the 1M context tier. issue #5865 was marked completed and states that follow-up work is tracked in another per-model context window and auto-compact sync item.

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.