Claude Code Dual-Model API Configuration: Alibaba ModelStudio + DeepSeek
TopicsClaude CodeAPIDeepSeekQwenTutorial
Why Do You Need Two Models?
| Scenario | Recommended Model | Reason |
|---|---|---|
| Everyday coding | DeepSeek V3 | Extremely high cost-performance ratio, strong coding ability |
| Deep reasoning | DeepSeek R1 | Chain-of-thought reasoning, suited to complex problems |
| Chinese content | Qwen-Max | Alibaba ecosystem, top-tier Chinese capability |
| Long context | Qwen-Plus | 128K+ context, suited to large projects |
| Failover | Each backs up the other | Automatic switching when the API is rate limited |
Step 1: Get API Keys
Alibaba ModelStudio
- Open the ModelStudio console
- Select "Model Service" → "Activate Model Service"
- Recommended models to activate:
- qwen-max, the strongest Chinese-language model
- qwen-plus, balances performance and cost
- qwen-coder-plus, dedicated to code
- 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
- Open DeepSeek Platform
- Register or log in
- Create a Key on the "API Keys" page
- 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)
| Model | Input (per million tokens) | Output (per million tokens) |
|---|---|---|
| deepseek-chat (V3) | $0.14 | $0.28 |
| deepseek-reasoner (R1) | $0.55 | $2.19 |
ModelStudio Pricing
| Model | Input (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
| Issue | Solution |
|---|---|
| DeepSeek API 502 | Wait a few minutes and retry, or claude-switch qwen |
| ModelStudio rate limiting | Coding Plan users have a higher quota, or downgrade to qwen-plus |
| JSON format error | Use python3 -m json.tool to validate the configuration file |