推荐语
三步搞定个人AI助手!用DeepSeek API+飞书在本地部署OpenClaw,低成本高效能。 核心内容: 1. 详细安装步骤:从环境准备到OpenClaw部署 2. DeepSeek模型配置与飞书应用集成指南 3. 成本估算与日常使用技巧
杨芳贤
53AI创始人/腾讯云(TVP)最具价值专家
使用 DeepSeek API + 飞书,在 Mac/Linux/Windows 本地部署个人 AI 助手
📋 目录
准备工作
必需条件
- Windows: 下载安装 https://nodejs.org
- Linux:
sudo apt install nodejs npm 或 sudo yum install nodejs
- 访问 https://platform.deepseek.com
- 访问 https://www.feishu.cn 注册企业版
预估成本
- DeepSeek API: 约 ¥0.001/千 tokens(超低价)
- 电费: 约 ¥5-10/月(如果 24/7 运行)
月度预估: 轻度使用约 ¥10-30
第一步:安装 OpenClaw
1.1 全局安装
打开终端,执行:
npm install -g openclaw@latest
安装时间:约 1-2 分钟
1.2 验证安装
openclaw --version
应该显示版本号,例如:2026.2.26
1.3 安装飞书插件
openclaw plugins install @openclaw/feishu
第二步:配置 DeepSeek 模型
2.1 创建配置目录
mkdir -p ~/.openclaw
2.2 创建配置文件
方法一:使用命令创建(推荐)
cat > ~/.openclaw/openclaw.json << 'EOF'
{
"models": {
"mode": "merge",
"providers": {
"deepseek": {
"baseUrl": "https://api.deepseek.com/v1",
"apiKey": "你的DeepSeek密钥",
"api": "openai-completions",
"models": [
{
"id": "deepseek-chat",
"name": "DeepSeek Chat (v3)",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 2.8e-7,
"output": 4.2e-7,
"cacheRead": 2.8e-8,
"cacheWrite": 2.8e-7
},
"contextWindow": 128000,
"maxTokens": 8192
}
]
}
}
},
"Agents": {
"defaults": {
"model": {
"primary": "deepseek/deepseek-chat"
},
"models": {
"deepseek/deepseek-chat": {}
}
}
}
}
EOF
重要: 把 你的DeepSeek密钥 替换成你的实际 API 密钥(以 sk- 开头)
方法二:手动编辑
nano ~/.openclaw/openclaw.json
复制上面的 JSON 内容,修改 API 密钥后保存(Ctrl + O,回车,Ctrl + X)
2.3 验证配置
openclaw models list
应该能看到:deepseek/deepseek-chat
第三步:创建飞书应用
3.1 访问飞书开放平台
打开浏览器:https://open.feishu.cn/app
使用飞书账号登录,点击"开发者后台"
3.2 创建企业自建应用
- 应用名称:
OpenClaw Bot(或你喜欢的名字)
3.3 获取应用凭证
在应用详情页面,点击"凭证与基础信息":
- 复制 App ID(格式:
cli_xxxxxxxxxx)
重要: 将这两个值保存到记事本,稍后会用到。
3.4 配置应用权限
{
"scopes": {
"tenant": [
"contact:user.base:readonly",
"contact:contact.base:readonly",
"im:chat",
"im:message",
"im:message.group_at_msg:readonly",
"im:message.p2p_msg:readonly",
"im:message:send_as_bot"
],
"user": []
}
}
3.5 配置机器人
3.6 配置事件订阅
重要:需要先启动 OpenClaw 建立连接,才能添加事件。
暂时跳过这一步,在第四步配置完 OpenClaw 并启动后再回来完成。
3.7 暂时不发布应用
注意:先不要发布应用,等配置完 OpenClaw 并添加事件订阅后再发布。
第四步:连接飞书与 OpenClaw
4.1 配置飞书频道
使用命令行配置(替换为你的实际 App ID 和 Secret):
openclaw config set channels.feishu.enabled true
openclaw config set channels.feishu.accounts.main.appId "cli_你的AppID"
openclaw config set channels.feishu.accounts.main.appSecret "你的AppSecret"
openclaw config set channels.feishu.accounts.main.botName "OpenClaw Bot"
openclaw config set plugins.entries.feishu.enabled true
4.2 设置访问策略(暂时跳过)
注意: 这一步暂时跳过,等获取到你的飞书用户 ID 后再配置。
默认配置会阻止未授权用户,我们需要先获取用户 ID,然后添加到白名单。
4.3 设置 Gateway 模式
openclaw config set gateway.mode local
4.4 配置工作目录(重要)
OpenClaw 默认只能在工作目录内操作文件。设置工作目录:
选项一:使用桌面作为工作目录(推荐)
openclaw config set agents.defaults.workspace "~/Desktop"
或者使用完整路径:
openclaw config set agents.defaults.workspace "/Users/你的用户名/Desktop"
选项二:使用默认工作目录
openclaw config set agents.defaults.workspace "~/.openclaw/workspace"
文件会创建在 ~/.openclaw/workspace 目录下。
选项三:使用其他目录
openclaw config set agents.defaults.workspace "/path/to/your/folder"
说明:
- 如果尝试访问工作目录外的文件,会报错:
Path escapes workspace root
第五步:启动和测试
5.1 启动 Gateway
openclaw gateway --port 18789 --verbose
成功标志:看到以下日志
Gateway listening on 127.0.0.1:18789
feishu[main]: WebSocket client started
ws client ready
5.2 回到飞书开放平台添加事件
现在 OpenClaw 已经启动并建立了长连接,回到飞书开放平台:
- 搜索并添加:
im.message.receive_v1(接收消息)
5.3 发布飞书应用
5.4 在飞书中找到机器人
5.5 获取飞书用户 ID
查看运行 Gateway 的终端日志,会看到类似:
feishu[main]: received message from ou_e34e1249c5d5b8af8ec7767a792231db
feishu[main]: blocked unauthorized sender ou_e34e1249c5d5b8af8ec7723a792661db
或者机器人会返回:
OpenClaw: access not configured.
Your Feishu user id: ou_e34e1249c5d5b8af8ec7237a792661db
Pairing code: P42TJJ78
5.6 配置白名单
打开新终端(保持 Gateway 运行),执行:
openclaw config set channels.feishu.dmPolicy allowlist
openclaw config set channels.feishu.allowFrom '["ou_你的用户ID"]'
例如:
openclaw config set channels.feishu.dmPolicy allowlist
openclaw config set channels.feishu.allowFrom '["ou_e34e1249c5d5b8af8ec77623792661db"]'
如果有多个用户需要使用:
openclaw config set channels.feishu.allowFrom '["ou_用户1", "ou_用户2", "ou_用户3"]'
5.7 重启 Gateway
在运行 Gateway 的终端按 Ctrl + C 停止,然后重新启动:
openclaw gateway --port 18789 --verbose
5.8 测试对话
重启 Gateway 后,在飞书中再次发送消息:
你好,请介绍一下自己
这次机器人应该会正常回复了!
在飞书中发送消息:
你好,请介绍一下自己
如果一切正常,机器人会用 DeepSeek 模型回复你!
日常使用
启动 Gateway
前台运行(查看日志)
openclaw gateway --port 18789 --verbose
按 Ctrl + C 停止
后台运行(推荐)
nohup openclaw gateway --port 18789 --verbose > ~/openclaw.log 2>&1 &
查看日志:
tail -f ~/openclaw.log
停止后台进程:
pkill -f "openclaw gateway"
设置开机自启(可选)
Mac/Linux
openclaw daemon install
openclaw daemon start
查看状态:
openclaw daemon status
停止服务:
openclaw daemon stop
卸载服务:
openclaw daemon uninstall
常用命令
# 查看 Gateway 状态
openclaw gateway status
# 重启 Gateway
openclaw gateway restart
# 查看模型列表
openclaw models list
# 查看配置
openclaw config get
# 查看日志
openclaw logs --follow
# 查看配对列表
openclaw pairing list feishu
# 运行诊断
openclaw doctor
在飞书中可以做什么
基础对话
OpenClaw 可以像 ChatGPT 一样进行对话:
你:帮我写一个 Python 函数计算斐波那契数列
AI:[生成代码]
你:请添加缓存优化
AI:[优化后的代码]
你:再添加单元测试
AI:[带测试的完整代码]
多轮对话
OpenClaw 会自动记住上下文,支持连续对话。
飞书聊天命令
在飞书中可以使用以下命令:
/status # 查看会话状态(模型、tokens、成本)
/new 或 /reset # 重置会话,清空上下文
/compact # 压缩上下文,节省 tokens
/think high # 设置思考级别(off/minimal/low/medium/high/xhigh)
/verbose on # 开启详细模式
/usage full # 显示使用统计
实际应用场景
1. 编程助手
帮我写一个 React 组件,实现一个可拖拽的卡片列表
2. 文档处理
帮我总结这段文字的要点:[粘贴长文本]
3. 数据分析
这组数据的平均值、中位数和标准差是多少?
[1, 5, 3, 8, 2, 9, 4, 7, 6]
4. 翻译
把这段话翻译成英文:[中文内容]
5. 学习辅导
用简单的语言解释一下什么是区块链
6. 创意写作
帮我写一封专业的邮件,主题是申请远程工作
7. 问题解决
我的 Node.js 项目报错:Cannot find module 'express'
应该怎么解决?
群聊使用
配置群聊策略:
openclaw config set channels.feishu.groupPolicy "open"
openclaw config set channels.feishu.requireMention true
进阶配置
切换模型
如果你想使用 DeepSeek Reasoner(推理模型):
openclaw config set agents.defaults.model.primary "deepseek/deepseek-reasoner"
openclaw gateway restart
切换回普通模型:
openclaw config set agents.defaults.model.primary "deepseek/deepseek-chat"
openclaw gateway restart
添加多个模型
编辑配置文件 ~/.openclaw/openclaw.json,在 models.providers.deepseek.models 数组中添加:
{
"id": "deepseek-reasoner",
"name": "DeepSeek Reasoner (v3)",
"reasoning": true,
"input": ["text"],
"cost": {
"input": 2.8e-7,
"output": 4.2e-7,
"cacheRead": 2.8e-8,
"cacheWrite": 2.8e-7
},
"contextWindow": 128000,
"maxTokens": 65536
}
然后在 agents.defaults.models 中添加:
"deepseek/deepseek-reasoner": {}
安装技能(Skills)
查看可用技能:
openclaw skills list
安装技能:
openclaw skills install <skill-name>
查看已安装技能:
openclaw skills installed
配置上下文压缩
节省 tokens 和成本:
openclaw config set agents.defaults.compaction.mode safeguard
openclaw config set agents.defaults.compaction.maxTokens 50000
配置并发数
openclaw config set agents.defaults.maxConcurrent 4
查看完整配置
cat ~/.openclaw/openclaw.json
常见问题
Q1: Gateway 启动失败
症状: 执行 openclaw gateway 后立即退出
解决方案:
cat ~/.openclaw/openclaw.json | python -m json.tool
openclaw doctor
openclaw logs --follow
Q2: 飞书机器人不回复
排查步骤:
ps aux | grep openclaw
openclaw pairing list feishu
openclaw config get channels.feishu.allowFrom
tail -f ~/openclaw.log
Q3: DeepSeek API 调用失败
排查步骤:
openclaw config get models.providers.deepseek.apiKey
curl https://api.deepseek.com/v1/models \
-H "Authorization: Bearer 你的API密钥"
Q4: 每次重启都要重新配对
解决方案: 使用白名单模式
openclaw config set channels.feishu.dmPolicy allowlist
openclaw config set channels.feishu.allowFrom '["ou_你的用户ID"]'
Q5: 如何查看 API 使用量和成本
方法一: 在飞书中使用命令
/usage full
方法二: 访问 DeepSeek 控制台查看详细账单
Q6: Gateway 占用 CPU 过高
解决方案:
openclaw config set agents.defaults.maxConcurrent 2
openclaw config set agents.defaults.compaction.mode aggressive
Q7: 如何更新 OpenClaw
npm update -g openclaw
openclaw plugins update
openclaw gateway restart
Q8: 如何备份配置
cp ~/.openclaw/openclaw.json ~/openclaw-backup-$(date +%Y%m%d).json
恢复配置:
cp ~/openclaw-backup-20260301.json ~/.openclaw/openclaw.json
Q9: 如何完全卸载
# 停止服务
openclaw daemon stop
openclaw daemon uninstall
# 卸载软件
npm uninstall -g openclaw
# 删除配置(可选)
rm -rf ~/.openclaw
性能优化
减少内存占用
openclaw config set agents.defaults.compaction.mode safeguard
openclaw config set agents.defaults.compaction.maxTokens 50000
加快响应速度
使用更快的模型(deepseek-chat 比 deepseek-reasoner 快):
openclaw config set agents.defaults.model.primary "deepseek/deepseek-chat"
降低成本
- 使用 deepseek-chat 而不是 deepseek-reasoner
安全建议
1. 保护 API 密钥
不要在公开的地方分享配置文件,因为里面包含 API 密钥。
2. 使用白名单模式
openclaw config set channels.feishu.dmPolicy allowlist
openclaw config set channels.feishu.allowFrom '["ou_你的用户ID"]'
3. 定期更新
npm update -g openclaw
4. 监控使用量
定期检查 DeepSeek 控制台,设置预算告警。
5. 备份配置
定期备份 ~/.openclaw/openclaw.json。
故障排查流程
步骤 1: 检查 Gateway 状态
openclaw gateway status
步骤 2: 查看日志
tail -n 50 ~/openclaw.log
步骤 3: 运行诊断
openclaw doctor
步骤 4: 验证配置
openclaw config get
openclaw models list
步骤 5: 测试 API
curl https://api.deepseek.com/v1/models \
-H "Authorization: Bearer 你的API密钥"
步骤 6: 重启 Gateway
pkill -f "openclaw gateway"
openclaw gateway --port 18789 --verbose
命令速查表
Gateway 管理
# 前台启动(查看日志)
openclaw gateway --port 18789 --verbose
# 后台启动
nohup openclaw gateway --port 18789 --verbose > ~/openclaw.log 2>&1 &
# 查看状态
openclaw gateway status
# 重启
openclaw gateway restart
# 停止
pkill -f "openclaw gateway"
# 查看日志
tail -f ~/openclaw.log
配置管理
# 查看所有配置
openclaw config get
# 查看特定配置
openclaw config get channels.feishu
# 设置配置
openclaw config set <key> <value>
# 查看模型列表
openclaw models list
# 运行诊断
openclaw doctor
配对管理
# 查看待配对请求
openclaw pairing list feishu
# 批准配对
openclaw pairing approve feishu <CODE>
# 拒绝配对
openclaw pairing reject feishu <CODE>
# 查看已配对设备
openclaw pairing list --approved
插件和技能
# 列出已安装插件
openclaw plugins list
# 安装插件
openclaw plugins install <plugin-name>
# 更新插件
openclaw plugins update
# 列出可用技能
openclaw skills list
# 安装技能
openclaw skills install <skill-name>
# 查看已安装技能
openclaw skills installed
守护进程(开机自启)
# 安装守护进程
openclaw daemon install
# 启动守护进程
openclaw daemon start
# 停止守护进程
openclaw daemon stop
# 查看状态
openclaw daemon status
# 卸载守护进程
openclaw daemon uninstall
日志和调试
# 查看实时日志
openclaw logs --follow
# 查看最近日志
tail -n 50 ~/openclaw.log
# 搜索错误
grep -i error ~/openclaw.log
# 查看进程
ps aux | grep openclaw
完整配置文件示例
~/.openclaw/openclaw.json 完整示例:
{
"meta": {
"lastTouchedVersion": "2026.2.26",
"lastTouchedAt": "2026-03-01T14:54:40.715Z"
},
"models": {
"mode": "merge",
"providers": {
"deepseek": {
"baseUrl": "https://api.deepseek.com/v1",
"apiKey": "sk-your-api-key-here",
"api": "openai-completions",
"models": [
{
"id": "deepseek-chat",
"name": "DeepSeek Chat (v3)",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 2.8e-7,
"output": 4.2e-7,
"cacheRead": 2.8e-8,
"cacheWrite": 2.8e-7
},
"contextWindow": 128000,
"maxTokens": 8192
},
{
"id": "deepseek-reasoner",
"name": "DeepSeek Reasoner (v3)",
"reasoning": true,
"input": ["text"],
"cost": {
"input": 2.8e-7,
"output": 4.2e-7,
"cacheRead": 2.8e-8,
"cacheWrite": 2.8e-7
},
"contextWindow": 128000,
"maxTokens": 65536
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "deepseek/deepseek-chat"
},
"models": {
"deepseek/deepseek-chat": {},
"deepseek/deepseek-reasoner": {}
},
"compaction": {
"mode": "safeguard",
"maxTokens": 100000
},
"maxConcurrent": 4
}
},
"channels": {
"feishu": {
"enabled": true,
"dmPolicy": "allowlist",
"allowFrom": ["ou_your_user_id_here"],
"groupPolicy": "open",
"requireMention": true,
"accounts": {
"main": {
"appId": "cli_your_app_id_here",
"appSecret": "your_app_secret_here",
"botName": "OpenClaw Bot"
}
}
}
},
"gateway": {
"mode": "local",
"port": 18789,
"bind": "127.0.0.1"
},
"plugins": {
"entries": {
"feishu": {
"enabled": true
}
}
}
}
相关链接
- OpenClaw 官网: https://openclaw.ai
- OpenClaw GitHub: https://github.com/openclaw/openclaw
- OpenClaw 文档: https://docs.openclaw.ai
- DeepSeek 平台: https://platform.deepseek.com
- DeepSeek API 文档: https://api-docs.deepseek.com
- 飞书开放平台: https://open.feishu.cn
- 飞书开发文档: https://open.feishu.cn/document
总结
恭喜!你已经成功在本地部署了 OpenClaw。现在你拥有:
✅ 一个运行在本地的 AI 助手
✅ 使用超低价的 DeepSeek API
✅ 通过飞书随时随地访问
✅ 完全掌控的私有部署
下一步建议
- 安装技能:
openclaw skills list 查看可用技能
- 设置开机自启:
openclaw daemon install && openclaw daemon start
- 定期备份配置:
cp ~/.openclaw/openclaw.json ~/backup/
如果需要 24/7 运行
本地部署需要电脑一直开着。如果需要 24/7 运行,可以考虑:
- Oracle Cloud 永久免费 VPS(推荐,真正的 24/7,完全免费)
享受你的 AI 助手吧!🦞
最后欢迎大家一起来学习 企业级前端AI和基建项目实战!已经有很多小伙伴拿到了Offer。包括字节、阿里等大厂。