Agentic Research

Claude Code Dual-Model API Configuration: Alibaba ModelStudio + DeepSeek

2026/05/0916 min readBryan Chan閱讀中文原文
TopicsClaude CodeAPIDeepSeekQwenTutorial

Why Do You Need Two Models?

ScenarioRecommended ModelReason
Everyday codingDeepSeek V3Extremely high cost-performance ratio, strong coding ability
Deep reasoningDeepSeek R1Chain-of-thought reasoning, suited to complex problems
Chinese contentQwen-MaxAlibaba ecosystem, top-tier Chinese capability
Long contextQwen-Plus128K+ context, suited to large projects
FailoverEach backs up the otherAutomatic switching when the API is rate limited

Step 1: Get API Keys

Alibaba ModelStudio

  1. Open the ModelStudio console
  2. Select "Model Service" → "Activate Model Service"
  3. Recommended models to activate:
    • qwen-max, the strongest Chinese-language model
    • qwen-plus, balances performance and cost
    • qwen-coder-plus, dedicated to code
  4. Create a Key under "API-KEY Management"

We recommend choosing the Coding Plan: if you mainly use it for development, ModelStudio's Coding Plan offers higher concurrency and priority.

DeepSeek

  1. Open DeepSeek Platform
  2. Register or log in
  3. Create a Key on the "API Keys" page
  4. Top up (DeepSeek pricing is extremely low, $0.14/M input tokens)

Step 2: Configure Claude Code

2.1 Global Configuration File

Create or edit ~/.claude.json:

{
  "apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxx",
  "baseURL": "https://api.deepseek.com/v1",
  "model": "deepseek-chat"
}

2.2 Multi-Model Switching Script

Create ~/bin/claude-switch:

#!/bin/bash
# Claude Code Model Switching Script
# Usage: claude-switch [deepseek|qwen|modelstudio]

case "$1" in
  deepseek)
    cat > ~/.claude.json << 'EOF'
{
  "apiKey": "sk-your-deepseek-key",
  "baseURL": "https://api.deepseek.com/v1",
  "model": "deepseek-chat"
}
EOF
echo "✓ Switched to DeepSeek V3"
    ;;

  deepseek-r1)
    cat > ~/.claude.json << 'EOF'
{
  "apiKey": "sk-your-deepseek-key",
  "baseURL": "https://api.deepseek.com/v1",
  "model": "deepseek-reasoner"
}
EOF
echo "✓ Switched to DeepSeek R1 (reasoning mode)"
    ;;

  qwen)
    cat > ~/.claude.json << 'EOF'
{
  "apiKey": "sk-your-modelstudio-key",
  "baseURL": "https://dashscope.aliyuncs.com/compatible-mode/v1",
  "model": "qwen-max"
}
EOF
echo "✓ Switched to Qwen-Max (ModelStudio)"
    ;;

  qwen-coder)
    cat > ~/.claude.json << 'EOF'
{
  "apiKey": "sk-your-modelstudio-key",
  "baseURL": "https://dashscope.aliyuncs.com/compatible-mode/v1",
  "model": "qwen-coder-plus"
}
EOF
echo "✓ Switched to Qwen-Coder-Plus"
    ;;

  *)
echo "Usage: claude-switch [deepseek|deepseek-r1|qwen|qwen-coder]"
    echo ""
echo "Current configuration:"
    cat ~/.claude.json | python3 -m json.tool 2>/dev/null || cat ~/.claude.json
    ;;
esac
chmod +x ~/bin/claude-switch

2.3 Shell Aliases

Append to ~/.zshrc:

# Quick Model Switching in Claude Code
alias cc-deepseek='claude-switch deepseek'
alias cc-r1='claude-switch deepseek-r1'
alias cc-qwen='claude-switch qwen'
alias cc-coder='claude-switch qwen-coder'

# View Current Model
alias cc-which='cat ~/.claude.json | python3 -m json.tool 2>/dev/null || cat ~/.claude.json'

Step 3: Dual-Model Configuration in OpenClaw

Configure the model routing strategy at the OpenClaw level:

~/.openclaw/openclaw.json:

{
  "routing": {
    "default_provider": "deepseek",
"rules": [
      {
"pattern": "*.zh.*|translate|Chinese",
        "provider": "modelstudio",
        "model": "qwen-max"
      },
      {
        "pattern": "code|refactor|debug|review",
        "provider": "deepseek",
        "model": "deepseek-chat"
      },
      {
        "pattern": "complex|analyze|design|architecture",
        "provider": "deepseek",
        "model": "deepseek-reasoner"
      }
    ],
    "fallback": {
      "enabled": true,
      "order": ["deepseek", "modelstudio"]
    }
  }
}

This way OpenClaw will automatically select the most suitable model based on the task content.


Step 4: Cost Control

DeepSeek Pricing (Extremely Low)

ModelInput (per million tokens)Output (per million tokens)
deepseek-chat (V3)$0.14$0.28
deepseek-reasoner (R1)$0.55$2.19

ModelStudio Pricing

ModelInput (per million tokens)Output (per million tokens)
qwen-max~$2.50~$10.00
qwen-plus~$1.00~$4.00
qwen-coder-plus~$1.50~$6.00

Money-Saving Tips

# Set a Daily Budget Cap in OpenClaw
openclaw config set budget.daily_limit 5.00
openclaw config set budget.warn_threshold 0.8

Step 5: Verification

# Test DeepSeek
cc-deepseek
echo "Hello, what model are you?" | claude

# Test Qwen
cc-qwen
echo "Hello, what model are you?" | claude

# Claude Code Interactive Mode Test
cc-deepseek && claude

Troubleshooting

IssueSolution
DeepSeek API 502Wait a few minutes and retry, or claude-switch qwen
ModelStudio rate limitingCoding Plan users have a higher quota, or downgrade to qwen-plus
JSON format errorUse python3 -m json.tool to validate the configuration file