Skip to main content

首页 / Posts

[Claude Code Router] Connect Five Major Models with One Router

A Claude Code Router tutorial for Gemini, Kimi, DeepSeek, GLM, and Qwen, covering CCR configuration, PROXY_URL, Anthropic versus OpenAI endpoints, /model switching, and common errors.

Rosetears·
··784 words·4 mins

Introduction
#

This guide shows how to configure Gemini 2.5 Pro, DeepSeek-V3.1, GLM-4.5, Kimi-K2, and Qwen3-Coder (ModelScope) direct APIs inside Claude Code Router (CCR), then switch models through the UI dropdown or /model command.

Claude Code natively expects the Anthropic message format (/v1/messages). CCR converts protocols on the backend and adapts OpenAI-compatible or vendor-specific APIs. Most providers in this guide therefore use /v1/chat/completions or vendor-specific endpoints; Gemini needs the dedicated CCR gemini transformer.

If you use an Anthropic-format URL, select the Anthropic transformer and make the Base URL end with /v1/messages. If you do not choose that transformer, use an OpenAI-compatible chat-completions endpoint and select openai.

Common Anthropic-format examples:

  • DeepSeek: https://api.deepseek.com/anthropic/v1/messages
  • Zhipu: https://open.bigmodel.cn/api/anthropic/v1/messages

1. Environment and startup
#

Install Claude Code and Claude Code Router globally with npm, then run ccr ui. CCR opens a local web interface at http://localhost:3456 by default. In the Providers list, add one configuration per model. Usually only Base URL and API Key are required; keep other options default at first.

If you do not want to store keys in the config file, set environment variables temporarily. You can also edit config.json directly at %USERPROFILE%\.claude-code-router\config.json on Windows or ~/.claude-code-router/config.json on macOS/Linux.


2. Five model configurations
#

2.1 Gemini 2.5 Pro
#

Get a key from Google AI Studio. Use:

  • Base URL: https://generativelanguage.googleapis.com/v1beta/models/
  • Models: gemini-2.5-pro, gemini-2.5-flash
  • Transformer: gemini

If the connection fails, try configuring PROXY_URL at the top level of config.json or enable TUN mode in your proxy client.

2.2 DeepSeek-V3.1
#

Get a key from DeepSeek platform.

Anthropic mode uses transformer Anthropic and Base URL https://api.deepseek.com/anthropic/v1/messages, with model deepseek-chat or deepseek-reasoner. OpenAI-compatible mode uses transformer openai and Base URL https://api.deepseek.com/chat/completions.

2.3 GLM-4.5 (Zhipu)
#

Get a key from Zhipu AI. Anthropic mode uses https://open.bigmodel.cn/api/anthropic/v1/messages; OpenAI-compatible mode uses https://open.bigmodel.cn/api/paas/v4/chat/completions. If you see an error about v1/completions, switch to /v4/chat/completions.

2.4 Kimi-K2
#

Get a key from Moonshot AI. Initial testing suggests Anthropic-format mode uses kimi-k2-turbo-preview, while OpenAI-compatible mode uses kimi-k2-0711-preview. Check Base URL and transformer if you see 404 or endpoint mismatch errors.

2.5 Qwen3-Coder (ModelScope)
#

Get a key from ModelScope. Use OpenAI-compatible transformer, Base URL https://api-inference.modelscope.cn/v1/chat/completions, and model Qwen/Qwen3-Coder-480B-A35B-Instruct or the current available model name.


3. Connectivity test
#

  1. Save the provider in CCR UI.
  2. Open a conversation with ccr code.
  3. Send a simple test message.
  4. A normal streaming response means the route works.

4. Common errors
#

  • 401 Unauthorized: key is empty, invalid, or for the wrong endpoint.
  • 403 Forbidden: account, region, or model permission is missing.
  • 429 Too Many Requests: rate or concurrency limit reached.
  • 5XX Server Error: provider-side instability; retry or switch region.
  • Chat model not supported in v1/completions: use /v1/chat/completions in OpenAI-compatible mode.
  • 404 on Anthropic path: write the Base URL all the way to /v1/messages to avoid duplicated path joining.

6. /model menu and self-identification
#

Inside Claude Code, /model may show only a few built-in options. You can still switch manually:

1
/model provider,model

For example:

1
/model deepseek,deepseek-chat

Non-Claude models may initially call themselves Sonnet because Claude Code’s system prompt says so. After switching with /model provider,model, model self-identification usually returns to normal.


Closing
#

You now have the minimum viable CCR setup for five major model providers and understand when to choose Anthropic versus OpenAI-compatible endpoints. Use /model provider,model to switch to the model best suited for reasoning, coding, or long-context work.

Preserved command, configuration, and prompt blocks
#

1
2
npm install -g @anthropic-ai/claude-code
npm install -g @musistudio/claude-code-router
1
ccr ui
1
%USERPROFILE%\.claude-code-router\config.json
1
~/.claude-code-router/config.json
1
2
3
4
5
6
7
{
  "name": "gemini",
  "api_base_url": "https://generativelanguage.googleapis.com/v1beta/models/",
  "api_key": "<YOUR_GEMINI_API_KEY>",
  "models": ["gemini-2.5-flash", "gemini-2.5-pro"],
  "transformer": { "use": ["gemini"] }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
  "PROXY_URL": "http://[redacted-ip]:7890",
  "Providers": [
    {
      "name": "gemini",
      "api_base_url": "https://generativelanguage.googleapis.com/v1beta/models/",
      "api_key": "<YOUR_GEMINI_API_KEY>",
      "models": ["gemini-2.5-flash", "gemini-2.5-pro"],
      "transformer": { "use": ["gemini"] }
    }
  ]
}
1
2
3
4
5
6
7
{
  "name": "deepseek-anthropic",
  "api_base_url": "https://api.deepseek.com/anthropic/v1/messages",
  "api_key": "<YOUR_DEEPSEEK_API_KEY>",
  "models": ["deepseek-chat"],
  "transformer": { "use": ["Anthropic"] }
}
1
2
3
4
5
6
{
  "name": "deepseek-openai",
  "api_base_url": "https://api.deepseek.com/chat/completions",
  "api_key": "<YOUR_DEEPSEEK_API_KEY>",
  "models": ["deepseek-chat", "deepseek-reasoner"],
}
1
2
3
4
5
6
7
{
  "name": "zhipu-anthropic",
  "api_base_url": "https://open.bigmodel.cn/api/anthropic/v1/messages",
  "api_key": "<YOUR_ZHIPU_API_KEY>",
  "models": ["glm-4.5"],
  "transformer": { "use": ["Anthropic"] }
}
1
2
3
4
5
6
{
  "name": "zhipu-openai",
  "api_base_url": "https://open.bigmodel.cn/api/paas/v4/chat/completions",
  "api_key": "<YOUR_ZHIPU_API_KEY>",
  "models": ["glm-4.5"],
}
1
2
3
4
5
6
7
{
  "name": "kimi-anthropic",
  "api_base_url": "https://api.moonshot.cn/anthropic/v1/messages",
  "api_key": "<YOUR_MOONSHOT_API_KEY>",
  "models": ["kimi-k2-turbo-preview"],
  "transformer": { "use": ["Anthropic"] }
}
1
2
3
4
5
6
7
{
  "name": "kimi-openai",
  "api_base_url": "https://api.moonshot.cn/v1/chat/completions",
  "api_key": "<YOUR_MOONSHOT_API_KEY>",
  "models": ["kimi-k2-0711-preview],
  "transformer": { "use": ["openai"] }
}
1
2
3
4
5
6
{
  "name": "modelscope",
  "api_base_url": "https://api-inference.modelscope.cn/v1/chat/completions",
  "api_key": "<YOUR_API_KEY>",
  "models": ["Qwen/Qwen3-Coder-480B-A35B-Instruct"],
}
1
/model provider,model
1
/model deepseek,deepseek-chat
1
/model provider,model

Related tools

Related