Skip to content

Local qwen3-coder model connection fails with 502 error - cc-switch

Quick fix

Claude Code requires Anthropic Messages; use a format-conversion proxy such as LiteLLM between cc-switch and the local model.

Error output
CC-Switch发送的请求与这个成功的curl请求有差异,导致502错误。
English translation

Requests sent by CC-Switch differ from the successful curl request, causing a 502 error.

The root cause is incompatible API formats. Claude Code uses Anthropic's Messages API format, while the local qwen3-coder model deployed through llama-server provides an OpenAI-compatible Chat Completions API format. Although curl and Cherry Studio can call the OpenAI-format endpoint, Claude Code sends Anthropic-format requests, which the local server cannot parse and therefore returns a 502 error. The maintainer identified this as an output-format mismatch between chat format and anthropic messages format.

  1. Deploy a format-conversion proxy such as LiteLLM as an intermediary to convert Claude Code Anthropic-format requests to the OpenAI format supported by the local model. Example command: litellm --model openai/qwen3-coder --api_base http://localhost:8080/v1 --port 4000

    cc-switch 配置\n{
    "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:4000",
    "ANTHROPIC_MODEL": "qwen3-coder"
    }
    }
  2. In cc-switch, point ANTHROPIC_BASE_URL to the local conversion proxy address, such as http://localhost:4000, instead of directly to the OpenAI-compatible endpoint of llama-server.

    cc-switch 配置\n{
    "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:4000"
    }
    }
  3. Keep the local llama-server running. The proxy layer converts the format and forwards requests to http://localhost:8080/v1.

Toolclaude-code
VersionUnknown
PlatformsmacOSLinuxWindows
Why can curl and Cherry Studio call the local model successfully, but cc-switch cannot?
curl and Cherry Studio use the OpenAI-compatible Chat Completions format, while Claude Code configured through cc-switch sends the Anthropic Messages format. The formats are incompatible.
Can I configure the OpenAI-compatible endpoint of local llama-server directly in cc-switch?
No. Claude Code requires the Anthropic format. Configuring an OpenAI endpoint directly causes a format mismatch and a 502 error, so a format-conversion proxy is required.

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.