OpenClaw 使用 DeepSeek 官方 API_KEY 配置教程

前言

找遍全网也没找到如何在openclaw配置deepseek官方apikey,那我自己整一个,以下内容为Claude Code根据我的聊天记录总结生成,希望对想在openclaw使用deepseek官方apikey的人提供帮助。

目录

  1. 系统要求
  2. [安装 OpenClaw](#安装 OpenClaw "#%E5%AE%89%E8%A3%85-openclaw")
  3. 初始化配置
  4. [配置 DeepSeek 官方 API](#配置 DeepSeek 官方 API "#%E9%85%8D%E7%BD%AE-deepseek-%E5%AE%98%E6%96%B9-api")
  5. 测试与使用
  6. 常用命令
  7. 故障排除

系统要求

  • 操作系统: macOS / Linux / Windows (WSL)
  • Node.js: 版本 22+ (推荐使用 nvm 管理)
  • 网络: 需要访问 DeepSeek API (api.deepseek.com)

安装 OpenClaw

1. 全局安装 OpenClaw

bash 复制代码
npm install -g openclaw@latest

安装过程可能需要 3-5 分钟,会下载约 674 个依赖包。

2. 验证安装

bash 复制代码
openclaw --version

应该显示类似:🦞 OpenClaw 2026.2.9


初始化配置

1. 运行配置向导

bash 复制代码
openclaw onboard --install-daemon --non-interactive --accept-risk

说明:

  • --install-daemon: 安装后台服务
  • --non-interactive: 非交互模式
  • --accept-risk: 接受安全风险声明

2. 检查服务状态

bash 复制代码
openclaw status

确认 Gateway 服务正在运行。


配置 DeepSeek 官方 API

1. 获取 DeepSeek API Key

访问 DeepSeek 官网 注册并获取 API Key。

API Key 格式类似:sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2. 配置 DeepSeek 提供商

执行以下命令(将 你的API_KEY 替换为实际的 API Key):

bash 复制代码
openclaw config set models.providers.deepseek '{
  "baseUrl": "https://api.deepseek.com/v1",
  "apiKey": "你的API_KEY",
  "api": "openai-completions",
  "models": [
    {
      "id": "deepseek-chat",
      "name": "DeepSeek Chat (V3)"
    },
    {
      "id": "deepseek-reasoner",
      "name": "DeepSeek Reasoner (R1)"
    }
  ]
}'

3. 设置默认模型

bash 复制代码
openclaw config set agents.defaults.model.primary "deepseek/deepseek-chat"

4. 创建模型别名(可选)

bash 复制代码
openclaw models aliases add deepseek-v3 "deepseek/deepseek-chat"
openclaw models aliases add deepseek-r1 "deepseek/deepseek-reasoner"

5. 重启 Gateway 服务

bash 复制代码
openclaw gateway restart

等待 3-5 秒让服务完全启动。


测试与使用

1. 命令行测试

bash 复制代码
openclaw agent --session-id test --message "你好,请介绍一下你自己"

如果配置成功,DeepSeek 会用中文回复。

2. 打开 Web 控制面板

bash 复制代码
openclaw dashboard

浏览器会自动打开控制面板,URL 格式:

perl 复制代码
http://127.0.0.1:18789/#token=你的gateway_token

3. 查看配置状态

bash 复制代码
openclaw models status

应该显示:

  • Default: deepseek/deepseek-chat
  • Configured models: 包含 deepseek 模型

常用命令

服务管理

bash 复制代码
# 启动 Gateway
openclaw gateway

# 重启 Gateway
openclaw gateway restart

# 停止 Gateway
openclaw gateway stop

# 查看服务状态
openclaw status

# 查看详细状态
openclaw status --all

# 查看实时日志
openclaw logs --follow

模型管理

bash 复制代码
# 列出所有可用模型
openclaw models list --all

# 查看当前模型配置
openclaw models status

# 切换模型(在聊天中使用)
/model deepseek-v3

# 设置默认模型
openclaw config set agents.defaults.model.primary "模型ID"

# 添加模型别名
openclaw models aliases add 别名 "模型ID"

# 查看所有别名
openclaw models aliases list

对话交互

bash 复制代码
# 发送单条消息
openclaw agent --session-id 会话ID --message "你的问题"

# 指定超时时间(秒)
openclaw agent --session-id test --message "问题" --timeout 60

# 使用本地模式(不通过 Gateway)
openclaw agent --local --session-id test --message "问题"

配置管理

bash 复制代码
# 查看配置
openclaw config get 配置路径

# 设置配置
openclaw config set 配置路径 "值"

# 删除配置
openclaw config unset 配置路径

# 运行配置向导
openclaw configure

故障排除

问题 1: Gateway Token 错误

错误信息 : disconnected (1008): unauthorized: gateway token missing

解决方法:

bash 复制代码
# 打开带 token 的控制面板
openclaw dashboard

或手动获取 token:

bash 复制代码
openclaw config get gateway.auth.token

问题 2: 模型不可用

错误信息 : Unknown model: xxx

解决方法:

  1. 检查模型配置:

    bash 复制代码
    openclaw models status
  2. 确认模型 ID 正确:

    bash 复制代码
    openclaw models list --all | grep deepseek
  3. 重启 Gateway:

    bash 复制代码
    openclaw gateway restart

问题 3: API Key 无效

错误信息 : HTTP 401Unauthorized

解决方法:

  1. 验证 API Key 是否正确

  2. 检查 API Key 是否过期

  3. 重新配置提供商:

    bash 复制代码
    openclaw config set models.providers.deepseek.apiKey "新的API_KEY"
    openclaw gateway restart

问题 4: 连接超时

错误信息 : Request timed outNo reply from agent

解决方法:

  1. 检查网络连接

  2. 测试 DeepSeek API 可达性:

    bash 复制代码
    curl -I https://api.deepseek.com/v1/models
  3. 增加超时时间:

    bash 复制代码
    openclaw agent --session-id test --message "测试" --timeout 120

问题 5: Gateway 无法启动

解决方法:

  1. 检查端口占用:

    bash 复制代码
    lsof -i :18789
  2. 强制重启:

    bash 复制代码
    openclaw gateway --force
  3. 查看日志:

    bash 复制代码
    openclaw logs
  4. 运行诊断:

    bash 复制代码
    openclaw doctor
    openclaw doctor --fix

高级配置

配置备用模型

当主模型不可用时,自动切换到备用模型:

bash 复制代码
openclaw config set agents.defaults.model.fallbacks '["deepseek/deepseek-reasoner"]'

配置环境变量

将以下内容添加到 ~/.zshrc~/.bashrc

bash 复制代码
# DeepSeek API Key (可选,如果已在配置文件中设置)
export DEEPSEEK_API_KEY="你的API_KEY"

# OpenClaw Gateway Token (可选)
export OPENCLAW_TOKEN="你的gateway_token"

然后重新加载配置:

bash 复制代码
source ~/.zshrc  # 或 source ~/.bashrc

配置工作空间

bash 复制代码
openclaw config set agents.defaults.workspace "/自定义/工作空间/路径"

相关资源

提示 : 如果遇到其他问题,可以运行 openclaw doctor --deep 进行深度诊断,或访问官方文档获取更多帮助。

相关推荐
张申傲3 小时前
拆解 harness9(9):Observability 可观测性
人工智能·aigc·agent·deepseek·harness
lincats3 小时前
SuperPower vs grill-me:AI编程圈两大skill正面交锋,你站哪边?
ai·codex·deepseek·vibe coding·skills
AC赳赳老秦1 天前
招投标公开数据自动化采集实战:基于 OpenClaw 的定时抓取与业务关键词精准推送
运维·服务器·数据库·自动化·测试用例·deepseek·openclaw
麦哲思科技任甲林1 天前
Codex+ChatGPT 胜过TRAE+DeepSeek组合的感受
chatgpt·deepseek·trae·工程化ai
正在走向自律2 天前
Deepseek V4 Flash 高效应用实战指南
人工智能·deepseek·deepseek v4·ai赋能中心
小月土星2 天前
1.0 从零构建 DeepSeek R1 WebGPU 浏览器推理应用:一次现代前端工程与端侧 AI 的深度碰撞
浏览器·deepseek
云卷云舒___________2 天前
阿里开源Qwen3.8 2.4T模型预览版、并推出Token Plan订阅、DeepSeek Harness与V4正式版同发 | 7月20日 AI日报
ai·阿里·deepseek·ai日报·harness·qwen38·tokenplan
不爱记笔记2 天前
2026 WAIC大会亮点解析!超节点、机器人与AI应用全面开花
人工智能·ai·机器人·具身智能·deepseek
CAE虚拟与现实3 天前
AI 编程助手的语境下Fork是什么意思?
人工智能·claude·codex·豆包·deepseek
李剑一3 天前
AI大模型扎堆上新?Kimi K3、Qwen 3.8、DeepSeek v4马上上线,旧的还没用上,新的就来了!比当年山寨机上新还快!
agent·ai编程·deepseek