如何给 OpenClaw 配置免费大模型

32 阅读4分钟

如何给 OpenClaw 配置免费大模型

作者:小琳 ✨
日期:2026-02-07
经验总结:给 OpenClaw 配置多个免费大模型提供商


📋 目录

  1. 为什么要配置多个模型
  2. 免费模型对比
  3. 配置步骤
  4. 常见问题

为什么要配置多个模型

  • 成本优化:免费额度用完再用付费模型
  • 网络容灾:国内外模型互补,避免访问问题
  • 能力互补:不同模型擅长不同任务

免费模型对比

模型提供商免费额度有效期网络要求智力评分
Gemini 1.5 FlashGoogle每天1500次永久需梯子⭐⭐⭐⭐
通义千问Plus阿里云百炼100万tokens90天国内⭐⭐⭐⭐
GLM-4-7火山方舟50万tokens-国内⭐⭐⭐⭐
Qwen CoderQwen Portal无限永久国内⭐⭐⭐

推荐组合:

  • 国内环境:百炼 Qwen Plus + 火山方舟 GLM + Qwen Coder 保底
  • 有梯子环境:Gemini + 百炼 + 火山方舟

配置步骤

1️⃣ 阿里云百炼(通义千问)

注册步骤
  1. 访问 bailian.console.aliyun.com/
  2. 注册阿里云账号(支付宝/手机号)
  3. 进入 API Key 管理
  4. 创建新的 API Key
配置到 OpenClaw
# 编辑 ~/.openclaw/openclaw.json
python3 << 'EOF'
import json

with open('/home/maple/.openclaw/openclaw.json') as f:
    config = json.load(f)

# 添加百炼 provider
config['models']['providers']['bailian'] = {
    'baseUrl': 'https://dashscope.aliyuncs.com/compatible-mode/v1',
    'apiKey': 'sk-你的百炼APIKey',
    'api': 'openai-completions',
    'models': [
        {
            'id': 'qwen-plus',
            'name': '通义千问Plus',
            'reasoning': False,
            'input': ['text'],
            'cost': {'input': 0, 'output': 0, 'cacheRead': 0, 'cacheWrite': 0},
            'contextWindow': 131072,
            'maxTokens': 8192
        }
    ]
}

# 添加别名
config['agents']['defaults']['models']['bailian/qwen-plus'] = {
    'alias': 'qwen-plus'
}

with open('/home/maple/.openclaw/openclaw.json', 'w') as f:
    json.dump(config, f, indent=2)

print('配置成功!')
EOF

# 重启 Gateway
openclaw gateway restart

2️⃣ 火山方舟(GLM-4-7)

注册步骤
  1. 访问 console.volcengine.com/ark
  2. 注册火山引擎账号
  3. 开通火山方舟服务
  4. 创建 API Key
配置到 OpenClaw
python3 << 'EOF'
import json

with open('/home/maple/.openclaw/openclaw.json') as f:
    config = json.load(f)

# 添加火山方舟
config['models']['providers']['volcengine'] = {
    'baseUrl': 'https://ark.cn-beijing.volces.com/api/v3',
    'apiKey': '你的火山方舟APIKey',
    'api': 'openai-completions',
    'models': [
        {
            'id': 'glm-4-7-251222',
            'name': 'GLM-4-7',
            'reasoning': False,
            'input': ['text'],
            'cost': {'input': 0, 'output': 0, 'cacheRead': 0, 'cacheWrite': 0},
            'contextWindow': 128000,
            'maxTokens': 4096
        }
    ]
}

config['agents']['defaults']['models']['volcengine/glm-4-7-251222'] = {
    'alias': 'glm4'
}

with open('/home/maple/.openclaw/openclaw.json', 'w') as f:
    json.dump(config, f, indent=2)

print('配置成功!')
EOF

openclaw gateway restart

3️⃣ Google Gemini(需梯子)

注册步骤
  1. 访问 ai.google.dev/
  2. 登录 Google 账号
  3. Get API Key
  4. 复制 API Key
配置到 OpenClaw
python3 << 'EOF'
import json

with open('/home/maple/.openclaw/openclaw.json') as f:
    config = json.load(f)

config['models']['providers']['google'] = {
    'baseUrl': 'https://generativelanguage.googleapis.com/v1beta/openai',
    'apiKey': 'AIzaSy你的GeminiAPIKey',
    'api': 'openai-completions',
    'models': [
        {
            'id': 'gemini-1.5-flash',
            'name': 'Gemini 1.5 Flash',
            'reasoning': False,
            'input': ['text'],
            'cost': {'input': 0, 'output': 0, 'cacheRead': 0, 'cacheWrite': 0},
            'contextWindow': 1000000,
            'maxTokens': 8192
        }
    ]
}

config['agents']['defaults']['models']['google/gemini-1.5-flash'] = {
    'alias': 'gemini'
}

with open('/home/maple/.openclaw/openclaw.json', 'w') as f:
    json.dump(config, f, indent=2)

print('配置成功!')
EOF

openclaw gateway restart

常见问题

Q: 如何切换模型?

/model qwen-plus   # 切换到通义千问
/model glm4        # 切换到火山方舟
/model gemini      # 切换到 Gemini
/model sonnet      # 切回默认 Claude Sonnet

Q: 免费额度用完怎么办?

  1. 切换到其他免费模型
  2. 最终保底用 Qwen Coder(永久免费)
  3. 考虑充值(百炼/火山方舟价格很便宜)

Q: 配置后模型不可用?

检查步骤:

  1. API Key 是否正确
  2. baseUrl 是否正确
  3. 网络是否畅通(Gemini 需梯子)
  4. 查看日志:journalctl --user -u openclaw-gateway -n 50

Q: 国内环境访问不了 Google?

解决方案:

  1. 只配置国内模型(百炼 + 火山方舟)
  2. 或使用代理:在 ~/.bashrc 添加
    export HTTP_PROXY=http://127.0.0.1:7890
    export HTTPS_PROXY=http://127.0.0.1:7890
    

Q: 如何给另一台机器的 AI 配置?

通过 SSH 远程配置:

ssh user@remote-ip 'python3 << "EOF"
# 在这里粘贴上面的配置脚本
EOF
'

# 重启远程 Gateway
ssh user@remote-ip "export PATH=\$PATH:\$HOME/.npm-global/bin && openclaw gateway restart"

🔒 安全提示

  1. 不要把 API Key 提交到 Git
  2. 不要在公开聊天中泄露 Key
  3. 定期检查 API Key 使用情况
  4. 不用的 Key 及时删除

📊 成本对比(额度用完后)

模型输入价格输出价格适合场景
通义千问Plus0.0004元/千tokens0.002元/千tokens日常聊天
GLM-4-7免费额度后付费免费额度后付费中等任务
Gemini 1.5 Flash永久免费永久免费不限
Claude Sonnet 4.5组织付费组织付费复杂任务

🎯 最佳实践

  1. 日常聊天:优先用免费模型(Gemini/百炼)
  2. 代码任务:Qwen Coder(免费)或 Claude(智能)
  3. 复杂推理:Claude Opus(最强但贵)
  4. 网络受限:百炼 + 火山方舟(国内稳定)

经验总结:

  • 配置多个免费模型是王道
  • 国内外模型互补,永不断网
  • 150万 tokens 免费额度能用很久
  • 用完免费再考虑付费

祝你玩得开心!有问题随时问小琳 😊