Hello everyone! Today I'm bringing you an ultra-practical tutorial - how to integrate domestic large models in OpenClaw to build a multi-model AI gateway that meets domestic compliance requirements.

Why Choose Domestic Large Models?

When deploying AI applications domestically, data security and compliance are the primary considerations. Domestic large models not only have fast response speeds and low costs, but more importantly, they can ensure data doesn't leave the country, fully complying with laws and regulations such as the "Network Security Law" and "Data Security Law".

Pre-Setup

Hardware Environment

  • Tencent Cloud Lighthouse Server (recommended 2 cores 4GB+ configuration)
  • Ubuntu 20.04 LTS system
  • OpenClaw basic environment installed

Software Dependencies

  • Node.js 18+
  • Docker (optional, for containerized deployment)
  • Latest version of OpenClaw

Domestic Large Model API Preparation

We need to prepare API keys for the following domestic large models:

  • Tongyi Qianwen (Qwen): Obtain from Alibaba Cloud Bailian Platform
  • Ernie Bot: Obtain from Baidu Intelligent Cloud Qianfan Large Model Platform
  • Xunfei Spark: Obtain from Xunfei Open Platform
  • GLM (Zhipu AI): Obtain from Zhipu AI Open Platform

⚠️ Important Reminder: All API keys must be securely stored through Tencent Cloud Key Management Service (KMS) or environment variables, never hardcode them in code!

Step 1: Configure OpenClaw Multi-Model Support

Add multi-model configuration in OpenClaw configuration file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
models:
# Tongyi Qianwen configuration
qwen-max:
provider: bailian
apiKey: ${QWEN_API_KEY}
baseUrl: https://dashscope.aliyuncs.com/api/v1

# Ernie Bot configuration
ernie-bot-4:
provider: baidu
apiKey: ${ERNIE_API_KEY}
secretKey: ${ERNIE_SECRET_KEY}

# Xunfei Spark configuration
spark-v3:
provider: xunfei
appId: ${SPARK_APP_ID}
apiSecret: ${SPARK_API_SECRET}
apiKey: ${SPARK_API_KEY}

# GLM configuration
glm-4:
provider: zhipu
apiKey: ${GLM_API_KEY}

Step 2: Implement Model Routing Logic

Create intelligent routing strategy to automatically select the most suitable model based on user needs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// model-router.js
const getModelForTask = (taskType, userPreference) => {
// Select model based on task type
switch(taskType) {
case 'coding':
return 'qwen-max'; // Tongyi Qianwen has strong coding ability
case 'creative':
return 'spark-v3'; // Xunfei Spark excels in creative writing
case 'analysis':
return 'glm-4'; // GLM has strong analytical reasoning ability
case 'general':
return userPreference || 'qwen-max';
default:
return 'qwen-max';
}
};

Step 3: Deploy to Tencent Cloud Lighthouse Server

Security Group Configuration

Ensure security group rules are correctly set:

  • Open HTTP(80) and HTTPS(443) ports
  • Restrict SSH(22) port to allow only specific IP access
  • Close unnecessary ports

Environment Variables Setting

1
2
3
4
5
# Set environment variables (through Tencent Cloud console or .env file)
export QWEN_API_KEY="your-qwen-api-key"
export ERNIE_API_KEY="your-ernie-api-key"
export SPARK_APP_ID="your-spark-app-id"
export GLM_API_KEY="your-glm-api-key"

Start Service

1
2
3
4
5
# Start OpenClaw service
npm start

# Or use PM2 process management
pm2 start index.js --name "openclaw-ai-gateway"

Step 4: Verify Multi-Model Functionality

Verify each model is working correctly through simple API tests:

1
2
3
4
5
6
7
8
9
# Test Tongyi Qianwen
curl -X POST http://localhost:3000/api/chat \
-H "Content-Type: application/json" \
-d '{"model": "qwen-max", "messages": [{"role": "user", "content": "Hello"}]}'

# Test Ernie Bot
curl -X POST http://localhost:3000/api/chat \
-H "Content-Type: application/json" \
-d '{"model": "ernie-bot-4", "messages": [{"role": "user", "content": "Hello"}]}'

Compliance Assurance Measures

Data Security

  • All user data processed at Tencent Cloud domestic nodes
  • Sensitive information automatically desensitized
  • Chat history encrypted storage, retention period not exceeding 30 days

Content Review

  • Integrated Tencent Cloud content security service
  • Real-time filtering of illegal content
  • Establish manual review backup mechanism

Real-Name Authentication

  • Require users to complete mobile phone real-name verification
  • Enterprise users must provide business license
  • Establish user behavior log audit

🎓 AI 编程实战课程

想系统学习 AI 编程?程序员晚枫的 AI 编程实战课 帮你从零上手!

Common Problem Troubleshooting