开启左侧

07-OpenClaw模型配置指南

[复制链接]
AI小编 发表于 3 小时前 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
作者:安逸 i
OpenClaw 模型配置指南

免费专栏全套教程:OpenClaw从入门到精通
OpenClaw 支持多种大语言模型(LLM)提供商,通过统一的接口配置和使用不同的 AI 模型。本指南将详细介绍如何配置和管理模型。

目录

    支持的模型列表配置模型 API Key切换模型方法模型参数配置多模型配置模型选择建议

1. 支持的模型列表

OpenClaw 支持以下模型提供商:
国际主流模型

提供商模型示例特点
Anthropicclaude-opus-4-6, claude-sonnet-4-5最强推理能力,支持 1M 上下文窗口
OpenAIgpt-5.1-codex, gpt-5.3-codexGPT 系列,支持 API 和 Codex 订阅
OpenRouter统一 API 接入多种模型单一 API Key 访问 100+ 模型
Venice AIllama-3.3-70b, claude-opus-45隐私优先,支持私有和匿名化代理
Together AIKimi-K2.5, deepseek-v3.1开源模型统一接口
Mistralmistral-large-latest欧洲开源模型,支持音频转录
Amazon Bedrockclaude-opus-4-6, llamaAWS 云端模型服务
中国本土模型

提供商模型示例特点
Qwen (通义千问)coder-model, vision-model免费层级,每日 2000 次请求
Moonshot (Kimi)kimi-k2.5, kimi-k2-thinking长上下文,支持编程模型
MiniMaxMiniMax-M2.1, MiniMax-M2.1-lightning多语言编程能力强
Z.AI (GLM)glm-5, glm-4.7智谱 AI 的 GLM 模型系列
Qianfan (千帆)百度智能云模型企业级 MaaS 平台
Xiaomi (小米)mimo-v2-flash262K 上下文,Anthropic 兼容
本地模型

提供商特点
Ollama本地运行开源模型,自动发现工具支持模型
vLLM高性能本地推理引擎

2. 配置模型 API Key

方式一:交互式配置(推荐)

使用 openclaw onboard 命令进行交互式配置:
  1. # 启动交互式配置向导
  2. openclaw onboard
  3. # 或直接指定提供商
  4. openclaw onboard --auth-choice anthropic-api-key
  5. openclaw onboard --auth-choice openai-api-key
  6. openclaw onboard --auth-choice qwen-portal
  7. openclaw onboard --auth-choice minimax-portal
  8. openclaw onboard --auth-choice moonshot-api-key
复制代码
方式二:环境变量配置

在配置文件或环境中设置 API Key:
  1. // ~/.openclaw/openclaw.json5
  2. {
  3.   env: {
  4.     ANTHROPIC_API_KEY: "sk-ant-...",
  5.     OPENAI_API_KEY: "sk-...",
  6.     MOONSHOT_API_KEY: "sk-...",
  7.     MINIMAX_API_KEY: "sk-...",
  8.     ZAI_API_KEY: "sk-...",
  9.     XIAOMI_API_KEY: "...",
  10.     TOGETHER_API_KEY: "...",
  11.     VENICE_API_KEY: "vapi_...",
  12.     OPENROUTER_API_KEY: "sk-or-...",
  13.     MISTRAL_API_KEY: "...",
  14.   },
  15. }
复制代码
方式三:Shell 环境变量
  1. # 临时设置exportANTHROPIC_API_KEY="sk-ant-..."exportOPENAI_API_KEY="sk-..."# 永久设置(添加到 ~/.zshrc 或 ~/.bashrc)echo'export ANTHROPIC_API_KEY="sk-ant-..."'>> ~/.zshrc
  2. source ~/.zshrc
复制代码
各提供商配置示例

Anthropic Claude
  1. # API Key 方式
  2. openclaw onboard --auth-choice anthropic-api-key
  3. # Claude 订阅 Token 方式
  4. openclaw onboard --auth-choice setup-token
  5. # 或运行
  6. claude setup-token  # 生成 token
  7. openclaw models auth paste-token --provider anthropic
复制代码
  1. {
  2.   env: { ANTHROPIC_API_KEY: "sk-ant-..." },
  3.   agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
  4. }
复制代码
OpenAI
  1. # API Key 方式
  2. openclaw onboard --auth-choice openai-api-key
  3. # Codex 订阅方式
  4. openclaw onboard --auth-choice openai-codex
复制代码
  1. {
  2.   env: { OPENAI_API_KEY: "sk-..." },
  3.   agents: { defaults: { model: { primary: "openai/gpt-5.1-codex" } } },
  4. }
复制代码
Qwen (通义千问)
  1. # 启用插件
  2. openclaw plugins enable qwen-portal-auth
  3. openclaw gateway restart
  4. # OAuth 登录
  5. openclaw models auth login --provider qwen-portal --set-default
复制代码
MiniMax
  1. # OAuth 方式(推荐)
  2. openclaw plugins enable minimax-portal-auth
  3. openclaw gateway restart
  4. openclaw onboard --auth-choice minimax-portal
  5. # API Key 方式
  6. openclaw onboard --auth-choice minimax-api-key
复制代码
  1. {
  2.   env: { MINIMAX_API_KEY: "sk-..." },
  3.   agents: { defaults: { model: { primary: "minimax/MiniMax-M2.1" } } },
  4. }
复制代码
Moonshot (Kimi)
  1. openclaw onboard --auth-choice moonshot-api-key
  2. # Kimi Coding
  3. openclaw onboard --auth-choice kimi-code-api-key
复制代码
  1. {
  2.   env: { MOONSHOT_API_KEY: "sk-..." },
  3.   agents: { defaults: { model: { primary: "moonshot/kimi-k2.5" } } },
  4. }
复制代码
Ollama (本地模型)
  1. # 安装 Ollama# 见 https://ollama.ai# 拉取模型
  2. ollama pull llama3.3
  3. ollama pull qwen2.5-coder:32b
  4. ollama pull deepseek-r1:32b
  5. # 设置环境变量(任意值即可)exportOLLAMA_API_KEY="ollama-local"
复制代码
  1. {
  2.   agents: { defaults: { model: { primary: "ollama/llama3.3" } } },
  3. }
复制代码

3. 切换模型方法

命令行切换
  1. # 查看可用模型列表
  2. openclaw models list
  3. # 切换默认模型
  4. openclaw models set anthropic/claude-opus-4-6
  5. openclaw models set openai/gpt-5.1-codex
  6. openclaw models set qwen-portal/coder-model
  7. openclaw models set minimax/MiniMax-M2.1
  8. openclaw models set ollama/llama3.3
  9. # 查看当前模型状态
  10. openclaw models status
复制代码
配置文件切换

编辑 ~/.openclaw/openclaw.json5:
  1. {
  2.   agents: {
  3.     defaults: {
  4.       model: {
  5.         primary: "anthropic/claude-opus-4-6",
  6.       },
  7.     },
  8.   },
  9. }
复制代码
交互式配置切换
  1. openclaw configure
  2. # 选择 Model/auth# 选择目标模型
复制代码
临时指定模型

在命令行中临时使用特定模型:
  1. # 单次对话使用特定模型
  2. openclaw agent --model venice/claude-opus-45 --message"你好"# 运行特定任务
  3. openclaw agent --model openai/gpt-5.2 --message"分析这段代码"
复制代码

4. 模型参数配置

基本参数配置

在 openclaw.json5 中配置模型参数:
  1. {
  2.   agents: {
  3.     defaults: {
  4.       models: {
  5.         "anthropic/claude-opus-4-6": {
  6.           alias: "opus",  // 模型别名
  7.           params: {
  8.             temperature: 0.7,      // 温度 (0-2)
  9.             maxTokens: 8192,       // 最大输出 token
  10.             topP: 0.9,             // Top-p 采样
  11.             topK: 40,             // Top-k 采样
  12.           },
  13.         },
  14.       },
  15.     },
  16.   },
  17. }
复制代码
Anthropic 特有参数

Prompt Caching(提示缓存)
  1. {
  2.   agents: {
  3.     defaults: {
  4.       models: {
  5.         "anthropic/claude-opus-4-6": {
  6.           params: {
  7.             cacheRetention: "long",  // "none" | "short"(5分钟) | "long"(1小时)
  8.           },
  9.         },
  10.       },
  11.     },
  12.   },
  13. }
复制代码
1M 上下文窗口
  1. {
  2.   agents: {
  3.     defaults: {
  4.       models: {
  5.         "anthropic/claude-opus-4-6": {
  6.           params: {
  7.             context1m: true,  // 启用 1M 上下文(beta 功能)
  8.           },
  9.         },
  10.       },
  11.     },
  12.   },
  13. }
复制代码
上下文窗口配置
  1. {
  2.   models: {
  3.     providers: {
  4.       anthropic: {
  5.         models: [
  6.           {
  7.             id: "claude-opus-4-6",
  8.             name: "Claude Opus 4.6",
  9.             reasoning: true,           // 是否支持推理
  10.             input: ["text", "image"],  // 支持的输入类型
  11.             contextWindow: 200000,     // 上下文窗口大小
  12.             maxTokens: 8192,           // 最大输出 token
  13.             cost: {
  14.               input: 15,      // 输入价格 ($/1M tokens)
  15.               output: 75,     // 输出价格
  16.               cacheRead: 1.5, // 缓存读取价格
  17.               cacheWrite: 18.75, // 缓存写入价格
  18.             },
  19.           },
  20.         ],
  21.       },
  22.     },
  23.   },
  24. }
复制代码
Z.AI 特有参数
  1. {
  2.   agents: {
  3.     defaults: {
  4.       models: {
  5.         "zai/glm-5": {
  6.           params: {
  7.             tool_stream: true,  // 工具调用流式传输(默认开启)
  8.           },
  9.         },
  10.       },
  11.     },
  12.   },
  13. }
复制代码

5. 多模型配置

主模型 + 备用模型

配置主模型失败时自动切换到备用模型:
  1. {
  2.   agents: {
  3.     defaults: {
  4.       models: {
  5.         "anthropic/claude-opus-4-6": { alias: "opus" },
  6.         "minimax/MiniMax-M2.1": { alias: "minimax" },
  7.         "openai/gpt-5.2": { alias: "gpt" },
  8.       },
  9.       model: {
  10.         primary: "anthropic/claude-opus-4-6",
  11.         fallbacks: [
  12.           "minimax/MiniMax-M2.1",
  13.           "openai/gpt-5.2",
  14.         ],
  15.       },
  16.     },
  17.   },
  18. }
复制代码
多提供商并行配置

同时配置多个模型提供商:
  1. {
  2.   env: {
  3.     ANTHROPIC_API_KEY: "sk-ant-...",
  4.     OPENAI_API_KEY: "sk-...",
  5.     MOONSHOT_API_KEY: "sk-...",
  6.     MINIMAX_API_KEY: "sk-...",
  7.     VENICE_API_KEY: "vapi_...",
  8.     OLLAMA_API_KEY: "ollama-local",
  9.   },
  10.   agents: {
  11.     defaults: {
  12.       models: {
  13.         // Anthropic
  14.         "anthropic/claude-opus-4-6": { alias: "opus" },
  15.         "anthropic/claude-sonnet-4-5": { alias: "sonnet" },
  16.         // OpenAI
  17.         "openai/gpt-5.1-codex": { alias: "gpt5" },
  18.         // 中国模型
  19.         "moonshot/kimi-k2.5": { alias: "kimi" },
  20.         "minimax/MiniMax-M2.1": { alias: "minimax" },
  21.         "zai/glm-5": { alias: "glm" },
  22.         // 隐私优先
  23.         "venice/llama-3.3-70b": { alias: "venice" },
  24.         // 本地模型
  25.         "ollama/llama3.3": { alias: "local" },
  26.       },
  27.       model: {
  28.         primary: "anthropic/claude-opus-4-6",
  29.         fallbacks: ["minimax/MiniMax-M2.1", "openai/gpt-5.1-codex"],
  30.       },
  31.     },
  32.   },
  33. }
复制代码
按场景配置不同模型
  1. {
  2.   agents: {
  3.     defaults: {
  4.       model: { primary: "anthropic/claude-opus-4-6" },
  5.     },
  6.     list: [
  7.       // 编程任务使用 MiniMax
  8.       {
  9.         id: "coder",
  10.         default: true,
  11.         model: { primary: "minimax/MiniMax-M2.1" },
  12.       },
  13.       // 快速任务使用轻量模型
  14.       {
  15.         id: "quick",
  16.         model: { primary: "anthropic/claude-sonnet-4-5" },
  17.       },
  18.       // 隐私敏感任务使用本地模型
  19.       {
  20.         id: "private",
  21.         model: { primary: "ollama/llama3.3" },
  22.       },
  23.       // 中国用户使用国内模型
  24.       {
  25.         id: "china",
  26.         model: { primary: "moonshot/kimi-k2.5" },
  27.       },
  28.     ],
  29.   },
  30. }
复制代码
模型分组策略
  1. {
  2.   agents: {
  3.     defaults: {
  4.       models: {
  5.         // === 高端模型(最强能力)===
  6.         "anthropic/claude-opus-4-6": {
  7.           alias: "opus",
  8.           tags: ["premium", "reasoning"],
  9.         },
  10.         "venice/claude-opus-45": {
  11.           alias: "opus-venice",
  12.           tags: ["premium", "privacy"],
  13.         },
  14.         
  15.         // === 平衡模型(性价比)===
  16.         "anthropic/claude-sonnet-4-5": {
  17.           alias: "sonnet",
  18.           tags: ["balanced"],
  19.         },
  20.         "minimax/MiniMax-M2.1": {
  21.           alias: "minimax",
  22.           tags: ["balanced", "coding"],
  23.         },
  24.         
  25.         // === 快速模型(低延迟)===
  26.         "venice/llama-3.3-70b": {
  27.           alias: "llama",
  28.           tags: ["fast", "privacy"],
  29.         },
  30.         "ollama/llama3.3": {
  31.           alias: "local",
  32.           tags: ["fast", "local", "privacy"],
  33.         },
  34.       },
  35.     },
  36.   },
  37. }
复制代码

6. 模型选择建议

按使用场景选择

场景推荐模型原因
复杂推理claude-opus-4-6最强推理能力
编程开发MiniMax-M2.1, kimi-k2.5多语言编程优化
日常对话claude-sonnet-4-5平衡性能和成本
隐私敏感venice/llama-3.3-70b, ollama/llama3.3完全私有
长文本处理kimi-k2.5 (256K), claude-opus-4-6 (1M)超大上下文
视觉理解qwen3-vl-235b-a22b, gpt-5.2-codex支持图像输入
中国用户kimi-k2.5, glm-5, MiniMax-M2.1国内服务,低延迟
按预算选择

预算推荐方案
免费Ollama 本地模型 + Qwen OAuth(每日 2000 次)
低成本MiniMax M2.1 + Venice Llama 3.3
中等预算Claude Sonnet + MiniMax 作为备用
高预算Claude Opus + GPT-5.2 双主
按地区选择

国际用户
  1. {
  2.   agents: {
  3.     defaults: {
  4.       model: {
  5.         primary: "anthropic/claude-opus-4-6",
  6.         fallbacks: ["openai/gpt-5.2", "venice/llama-3.3-70b"],
  7.       },
  8.     },
  9.   },
  10. }
复制代码
中国用户
  1. {
  2.   agents: {
  3.     defaults: {
  4.       model: {
  5.         primary: "moonshot/kimi-k2.5",
  6.         fallbacks: ["minimax/MiniMax-M2.1", "zai/glm-5"],
  7.       },
  8.     },
  9.   },
  10. }
复制代码
按隐私需求选择

隐私级别推荐方案
完全私有Ollama 本地模型
匿名化代理Venice 匿名模式(venice/claude-opus-45)
隐私优先Venice 私有模型(venice/llama-3.3-70b)
标准直接 API(Anthropic/OpenAI)
性能对比参考

模型推理能力编程能力速度上下文成本
Claude Opus 4.6⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐200K/1M$$$$$
Claude Sonnet 4.5⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐200K$$$
GPT-5.2⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐262K$$$$
MiniMax M2.1⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐200K$$
Kimi K2.5⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐256K$$
GLM 5⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐200K$$
Llama 3.3 70B⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐131K免费

完整配置示例
  1. // ~/.openclaw/openclaw.json5
  2. {
  3.   // 环境变量
  4.   env: {
  5.     ANTHROPIC_API_KEY: "sk-ant-...",
  6.     OPENAI_API_KEY: "sk-...",
  7.     MOONSHOT_API_KEY: "sk-...",
  8.     MINIMAX_API_KEY: "sk-...",
  9.     ZAI_API_KEY: "sk-...",
  10.     VENICE_API_KEY: "vapi_...",
  11.     OLLAMA_API_KEY: "ollama-local",
  12.   },
  13.   // 模型提供商配置
  14.   models: {
  15.     mode: "merge",  // 合并默认模型
  16.     providers: {
  17.       // MiniMax 配置
  18.       minimax: {
  19.         baseUrl: "https://api.minimax.io/anthropic",
  20.         api: "anthropic-messages",
  21.         models: [
  22.           {
  23.             id: "MiniMax-M2.1",
  24.             name: "MiniMax M2.1",
  25.             reasoning: true,
  26.             input: ["text"],
  27.             contextWindow: 200000,
  28.             maxTokens: 8192,
  29.             cost: { input: 15, output: 60, cacheRead: 2, cacheWrite: 10 },
  30.           },
  31.         ],
  32.       },
  33.       // Ollama 本地模型
  34.       ollama: {
  35.         baseUrl: "http://127.0.0.1:11434",
  36.         api: "ollama",
  37.         apiKey: "ollama-local",
  38.       },
  39.     },
  40.   },
  41.   // Agent 配置
  42.   agents: {
  43.     defaults: {
  44.       // 模型配置
  45.       models: {
  46.         "anthropic/claude-opus-4-6": {
  47.           alias: "opus",
  48.           params: { cacheRetention: "long" },
  49.         },
  50.         "anthropic/claude-sonnet-4-5": { alias: "sonnet" },
  51.         "minimax/MiniMax-M2.1": { alias: "minimax" },
  52.         "moonshot/kimi-k2.5": { alias: "kimi" },
  53.         "ollama/llama3.3": { alias: "local" },
  54.       },
  55.       
  56.       // 主模型和备用模型
  57.       model: {
  58.         primary: "anthropic/claude-opus-4-6",
  59.         fallbacks: [
  60.           "minimax/MiniMax-M2.1",
  61.           "moonshot/kimi-k2.5",
  62.           "ollama/llama3.3",
  63.         ],
  64.       },
  65.     },
  66.    
  67.     // 场景化 Agent
  68.     list: [
  69.       {
  70.         id: "coder",
  71.         model: { primary: "minimax/MiniMax-M2.1" },
  72.       },
  73.       {
  74.         id: "quick",
  75.         model: { primary: "anthropic/claude-sonnet-4-5" },
  76.       },
  77.       {
  78.         id: "private",
  79.         model: { primary: "ollama/llama3.3" },
  80.       },
  81.     ],
  82.   },
  83. }
复制代码

常见问题

Q: 如何查看当前使用的模型?
  1. openclaw models status
  2. openclaw models list
复制代码
Q: 模型切换后不生效?

重启 Gateway:
  1. openclaw gateway restart
复制代码
Q: API Key 配置后仍报错?

检查环境变量是否正确:
  1. # 查看环境变量echo$ANTHROPIC_API_KEY# 查看模型状态
  2. openclaw models status --json
复制代码
Q: 如何使用本地模型?
  1. # 1. 安装 Ollama
  2. brew install ollama  # macOS# 2. 启动服务
  3. ollama serve
  4. # 3. 拉取模型
  5. ollama pull llama3.3
  6. # 4. 设置环境变量exportOLLAMA_API_KEY="ollama-local"# 5. 切换模型
  7. openclaw models set ollama/llama3.3
复制代码
Q: 如何同时使用多个模型?

配置多个 API Key,使用别名切换:
  1. openclaw models set opus      # 切换到 claude-opus
  2. openclaw models set kimi      # 切换到 kimi-k2.5
  3. openclaw models set minimax   # 切换到 MiniMax
复制代码

参考链接

    OpenClaw 官方文档Anthropic API 文档OpenAI API 文档MiniMax 平台Kimi APIOllama 官网Venice AI




原文地址:https://blog.csdn.net/sgr011215/article/details/158495542
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

发布主题
阅读排行更多+

Powered by Discuz! X3.4© 2001-2013 Discuz Team.( 京ICP备17022993号-3 )