作者:安逸 i
OpenClaw 模型配置指南
免费专栏全套教程:OpenClaw从入门到精通
OpenClaw 支持多种大语言模型(LLM)提供商,通过统一的接口配置和使用不同的 AI 模型。本指南将详细介绍如何配置和管理模型。
目录
支持的模型列表配置模型 API Key切换模型方法模型参数配置多模型配置模型选择建议
1. 支持的模型列表
OpenClaw 支持以下模型提供商:
国际主流模型
| 提供商 | 模型示例 | 特点 | | Anthropic | claude-opus-4-6, claude-sonnet-4-5 | 最强推理能力,支持 1M 上下文窗口 | | OpenAI | gpt-5.1-codex, gpt-5.3-codex | GPT 系列,支持 API 和 Codex 订阅 | | OpenRouter | 统一 API 接入多种模型 | 单一 API Key 访问 100+ 模型 | | Venice AI | llama-3.3-70b, claude-opus-45 | 隐私优先,支持私有和匿名化代理 | | Together AI | Kimi-K2.5, deepseek-v3.1 | 开源模型统一接口 | | Mistral | mistral-large-latest | 欧洲开源模型,支持音频转录 | | Amazon Bedrock | claude-opus-4-6, llama | AWS 云端模型服务 | 中国本土模型
| 提供商 | 模型示例 | 特点 | | Qwen (通义千问) | coder-model, vision-model | 免费层级,每日 2000 次请求 | | Moonshot (Kimi) | kimi-k2.5, kimi-k2-thinking | 长上下文,支持编程模型 | | MiniMax | MiniMax-M2.1, MiniMax-M2.1-lightning | 多语言编程能力强 | | Z.AI (GLM) | glm-5, glm-4.7 | 智谱 AI 的 GLM 模型系列 | | Qianfan (千帆) | 百度智能云模型 | 企业级 MaaS 平台 | | Xiaomi (小米) | mimo-v2-flash | 262K 上下文,Anthropic 兼容 | 本地模型
| 提供商 | 特点 | | Ollama | 本地运行开源模型,自动发现工具支持模型 | | vLLM | 高性能本地推理引擎 |
2. 配置模型 API Key
方式一:交互式配置(推荐)
使用 openclaw onboard 命令进行交互式配置:- # 启动交互式配置向导
- openclaw onboard
- # 或直接指定提供商
- openclaw onboard --auth-choice anthropic-api-key
- openclaw onboard --auth-choice openai-api-key
- openclaw onboard --auth-choice qwen-portal
- openclaw onboard --auth-choice minimax-portal
- openclaw onboard --auth-choice moonshot-api-key
复制代码 方式二:环境变量配置
在配置文件或环境中设置 API Key:- // ~/.openclaw/openclaw.json5
- {
- env: {
- ANTHROPIC_API_KEY: "sk-ant-...",
- OPENAI_API_KEY: "sk-...",
- MOONSHOT_API_KEY: "sk-...",
- MINIMAX_API_KEY: "sk-...",
- ZAI_API_KEY: "sk-...",
- XIAOMI_API_KEY: "...",
- TOGETHER_API_KEY: "...",
- VENICE_API_KEY: "vapi_...",
- OPENROUTER_API_KEY: "sk-or-...",
- MISTRAL_API_KEY: "...",
- },
- }
复制代码 方式三:Shell 环境变量
- # 临时设置exportANTHROPIC_API_KEY="sk-ant-..."exportOPENAI_API_KEY="sk-..."# 永久设置(添加到 ~/.zshrc 或 ~/.bashrc)echo'export ANTHROPIC_API_KEY="sk-ant-..."'>> ~/.zshrc
- source ~/.zshrc
复制代码 各提供商配置示例
Anthropic Claude
- # API Key 方式
- openclaw onboard --auth-choice anthropic-api-key
- # Claude 订阅 Token 方式
- openclaw onboard --auth-choice setup-token
- # 或运行
- claude setup-token # 生成 token
- openclaw models auth paste-token --provider anthropic
复制代码- {
- env: { ANTHROPIC_API_KEY: "sk-ant-..." },
- agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
- }
复制代码 OpenAI
- # API Key 方式
- openclaw onboard --auth-choice openai-api-key
- # Codex 订阅方式
- openclaw onboard --auth-choice openai-codex
复制代码- {
- env: { OPENAI_API_KEY: "sk-..." },
- agents: { defaults: { model: { primary: "openai/gpt-5.1-codex" } } },
- }
复制代码 Qwen (通义千问)
- # 启用插件
- openclaw plugins enable qwen-portal-auth
- openclaw gateway restart
- # OAuth 登录
- openclaw models auth login --provider qwen-portal --set-default
复制代码 MiniMax
- # OAuth 方式(推荐)
- openclaw plugins enable minimax-portal-auth
- openclaw gateway restart
- openclaw onboard --auth-choice minimax-portal
- # API Key 方式
- openclaw onboard --auth-choice minimax-api-key
复制代码- {
- env: { MINIMAX_API_KEY: "sk-..." },
- agents: { defaults: { model: { primary: "minimax/MiniMax-M2.1" } } },
- }
复制代码 Moonshot (Kimi)
- openclaw onboard --auth-choice moonshot-api-key
- # Kimi Coding
- openclaw onboard --auth-choice kimi-code-api-key
复制代码- {
- env: { MOONSHOT_API_KEY: "sk-..." },
- agents: { defaults: { model: { primary: "moonshot/kimi-k2.5" } } },
- }
复制代码 Ollama (本地模型)
- # 安装 Ollama# 见 https://ollama.ai# 拉取模型
- ollama pull llama3.3
- ollama pull qwen2.5-coder:32b
- ollama pull deepseek-r1:32b
- # 设置环境变量(任意值即可)exportOLLAMA_API_KEY="ollama-local"
复制代码- {
- agents: { defaults: { model: { primary: "ollama/llama3.3" } } },
- }
复制代码 3. 切换模型方法
命令行切换
- # 查看可用模型列表
- openclaw models list
- # 切换默认模型
- openclaw models set anthropic/claude-opus-4-6
- openclaw models set openai/gpt-5.1-codex
- openclaw models set qwen-portal/coder-model
- openclaw models set minimax/MiniMax-M2.1
- openclaw models set ollama/llama3.3
- # 查看当前模型状态
- openclaw models status
复制代码 配置文件切换
编辑 ~/.openclaw/openclaw.json5:- {
- agents: {
- defaults: {
- model: {
- primary: "anthropic/claude-opus-4-6",
- },
- },
- },
- }
复制代码 交互式配置切换
- openclaw configure
- # 选择 Model/auth# 选择目标模型
复制代码 临时指定模型
在命令行中临时使用特定模型:- # 单次对话使用特定模型
- openclaw agent --model venice/claude-opus-45 --message"你好"# 运行特定任务
- openclaw agent --model openai/gpt-5.2 --message"分析这段代码"
复制代码 4. 模型参数配置
基本参数配置
在 openclaw.json5 中配置模型参数:- {
- agents: {
- defaults: {
- models: {
- "anthropic/claude-opus-4-6": {
- alias: "opus", // 模型别名
- params: {
- temperature: 0.7, // 温度 (0-2)
- maxTokens: 8192, // 最大输出 token
- topP: 0.9, // Top-p 采样
- topK: 40, // Top-k 采样
- },
- },
- },
- },
- },
- }
复制代码 Anthropic 特有参数
Prompt Caching(提示缓存)
- {
- agents: {
- defaults: {
- models: {
- "anthropic/claude-opus-4-6": {
- params: {
- cacheRetention: "long", // "none" | "short"(5分钟) | "long"(1小时)
- },
- },
- },
- },
- },
- }
复制代码 1M 上下文窗口
- {
- agents: {
- defaults: {
- models: {
- "anthropic/claude-opus-4-6": {
- params: {
- context1m: true, // 启用 1M 上下文(beta 功能)
- },
- },
- },
- },
- },
- }
复制代码 上下文窗口配置
- {
- models: {
- providers: {
- anthropic: {
- models: [
- {
- id: "claude-opus-4-6",
- name: "Claude Opus 4.6",
- reasoning: true, // 是否支持推理
- input: ["text", "image"], // 支持的输入类型
- contextWindow: 200000, // 上下文窗口大小
- maxTokens: 8192, // 最大输出 token
- cost: {
- input: 15, // 输入价格 ($/1M tokens)
- output: 75, // 输出价格
- cacheRead: 1.5, // 缓存读取价格
- cacheWrite: 18.75, // 缓存写入价格
- },
- },
- ],
- },
- },
- },
- }
复制代码 Z.AI 特有参数
- {
- agents: {
- defaults: {
- models: {
- "zai/glm-5": {
- params: {
- tool_stream: true, // 工具调用流式传输(默认开启)
- },
- },
- },
- },
- },
- }
复制代码 5. 多模型配置
主模型 + 备用模型
配置主模型失败时自动切换到备用模型:- {
- agents: {
- defaults: {
- models: {
- "anthropic/claude-opus-4-6": { alias: "opus" },
- "minimax/MiniMax-M2.1": { alias: "minimax" },
- "openai/gpt-5.2": { alias: "gpt" },
- },
- model: {
- primary: "anthropic/claude-opus-4-6",
- fallbacks: [
- "minimax/MiniMax-M2.1",
- "openai/gpt-5.2",
- ],
- },
- },
- },
- }
复制代码 多提供商并行配置
同时配置多个模型提供商:- {
- env: {
- ANTHROPIC_API_KEY: "sk-ant-...",
- OPENAI_API_KEY: "sk-...",
- MOONSHOT_API_KEY: "sk-...",
- MINIMAX_API_KEY: "sk-...",
- VENICE_API_KEY: "vapi_...",
- OLLAMA_API_KEY: "ollama-local",
- },
- agents: {
- defaults: {
- models: {
- // Anthropic
- "anthropic/claude-opus-4-6": { alias: "opus" },
- "anthropic/claude-sonnet-4-5": { alias: "sonnet" },
- // OpenAI
- "openai/gpt-5.1-codex": { alias: "gpt5" },
- // 中国模型
- "moonshot/kimi-k2.5": { alias: "kimi" },
- "minimax/MiniMax-M2.1": { alias: "minimax" },
- "zai/glm-5": { alias: "glm" },
- // 隐私优先
- "venice/llama-3.3-70b": { alias: "venice" },
- // 本地模型
- "ollama/llama3.3": { alias: "local" },
- },
- model: {
- primary: "anthropic/claude-opus-4-6",
- fallbacks: ["minimax/MiniMax-M2.1", "openai/gpt-5.1-codex"],
- },
- },
- },
- }
复制代码 按场景配置不同模型
- {
- agents: {
- defaults: {
- model: { primary: "anthropic/claude-opus-4-6" },
- },
- list: [
- // 编程任务使用 MiniMax
- {
- id: "coder",
- default: true,
- model: { primary: "minimax/MiniMax-M2.1" },
- },
- // 快速任务使用轻量模型
- {
- id: "quick",
- model: { primary: "anthropic/claude-sonnet-4-5" },
- },
- // 隐私敏感任务使用本地模型
- {
- id: "private",
- model: { primary: "ollama/llama3.3" },
- },
- // 中国用户使用国内模型
- {
- id: "china",
- model: { primary: "moonshot/kimi-k2.5" },
- },
- ],
- },
- }
复制代码 模型分组策略
- {
- agents: {
- defaults: {
- models: {
- // === 高端模型(最强能力)===
- "anthropic/claude-opus-4-6": {
- alias: "opus",
- tags: ["premium", "reasoning"],
- },
- "venice/claude-opus-45": {
- alias: "opus-venice",
- tags: ["premium", "privacy"],
- },
-
- // === 平衡模型(性价比)===
- "anthropic/claude-sonnet-4-5": {
- alias: "sonnet",
- tags: ["balanced"],
- },
- "minimax/MiniMax-M2.1": {
- alias: "minimax",
- tags: ["balanced", "coding"],
- },
-
- // === 快速模型(低延迟)===
- "venice/llama-3.3-70b": {
- alias: "llama",
- tags: ["fast", "privacy"],
- },
- "ollama/llama3.3": {
- alias: "local",
- tags: ["fast", "local", "privacy"],
- },
- },
- },
- },
- }
复制代码 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 双主 | 按地区选择
国际用户
- {
- agents: {
- defaults: {
- model: {
- primary: "anthropic/claude-opus-4-6",
- fallbacks: ["openai/gpt-5.2", "venice/llama-3.3-70b"],
- },
- },
- },
- }
复制代码 中国用户
- {
- agents: {
- defaults: {
- model: {
- primary: "moonshot/kimi-k2.5",
- fallbacks: ["minimax/MiniMax-M2.1", "zai/glm-5"],
- },
- },
- },
- }
复制代码 按隐私需求选择
| 隐私级别 | 推荐方案 | | 完全私有 | 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 | 免费 |
完整配置示例
- // ~/.openclaw/openclaw.json5
- {
- // 环境变量
- env: {
- ANTHROPIC_API_KEY: "sk-ant-...",
- OPENAI_API_KEY: "sk-...",
- MOONSHOT_API_KEY: "sk-...",
- MINIMAX_API_KEY: "sk-...",
- ZAI_API_KEY: "sk-...",
- VENICE_API_KEY: "vapi_...",
- OLLAMA_API_KEY: "ollama-local",
- },
- // 模型提供商配置
- models: {
- mode: "merge", // 合并默认模型
- providers: {
- // MiniMax 配置
- minimax: {
- baseUrl: "https://api.minimax.io/anthropic",
- api: "anthropic-messages",
- models: [
- {
- id: "MiniMax-M2.1",
- name: "MiniMax M2.1",
- reasoning: true,
- input: ["text"],
- contextWindow: 200000,
- maxTokens: 8192,
- cost: { input: 15, output: 60, cacheRead: 2, cacheWrite: 10 },
- },
- ],
- },
- // Ollama 本地模型
- ollama: {
- baseUrl: "http://127.0.0.1:11434",
- api: "ollama",
- apiKey: "ollama-local",
- },
- },
- },
- // Agent 配置
- agents: {
- defaults: {
- // 模型配置
- models: {
- "anthropic/claude-opus-4-6": {
- alias: "opus",
- params: { cacheRetention: "long" },
- },
- "anthropic/claude-sonnet-4-5": { alias: "sonnet" },
- "minimax/MiniMax-M2.1": { alias: "minimax" },
- "moonshot/kimi-k2.5": { alias: "kimi" },
- "ollama/llama3.3": { alias: "local" },
- },
-
- // 主模型和备用模型
- model: {
- primary: "anthropic/claude-opus-4-6",
- fallbacks: [
- "minimax/MiniMax-M2.1",
- "moonshot/kimi-k2.5",
- "ollama/llama3.3",
- ],
- },
- },
-
- // 场景化 Agent
- list: [
- {
- id: "coder",
- model: { primary: "minimax/MiniMax-M2.1" },
- },
- {
- id: "quick",
- model: { primary: "anthropic/claude-sonnet-4-5" },
- },
- {
- id: "private",
- model: { primary: "ollama/llama3.3" },
- },
- ],
- },
- }
复制代码 常见问题
Q: 如何查看当前使用的模型?
- openclaw models status
- openclaw models list
复制代码 Q: 模型切换后不生效?
重启 Gateway:Q: API Key 配置后仍报错?
检查环境变量是否正确:- # 查看环境变量echo$ANTHROPIC_API_KEY# 查看模型状态
- openclaw models status --json
复制代码 Q: 如何使用本地模型?
- # 1. 安装 Ollama
- brew install ollama # macOS# 2. 启动服务
- ollama serve
- # 3. 拉取模型
- ollama pull llama3.3
- # 4. 设置环境变量exportOLLAMA_API_KEY="ollama-local"# 5. 切换模型
- openclaw models set ollama/llama3.3
复制代码 Q: 如何同时使用多个模型?
配置多个 API Key,使用别名切换:- openclaw models set opus # 切换到 claude-opus
- openclaw models set kimi # 切换到 kimi-k2.5
- openclaw models set minimax # 切换到 MiniMax
复制代码 参考链接
OpenClaw 官方文档Anthropic API 文档OpenAI API 文档MiniMax 平台Kimi APIOllama 官网Venice AI
原文地址:https://blog.csdn.net/sgr011215/article/details/158495542 |