核心特点
- 开箱即用:内置多种流行AI服务(如 OpenAI、DeepSeek、智谱、月之暗面等)的快速配置。
- 模块化设计:通过子命令管理不同功能,如聊天、图像生成、模型列表等。
- 配置灵活:支持环境变量、配置文件等多种方式管理API密钥和模型偏好。
- 多模型支持:一个工具即可调用国内外数十种主流模型。
安装与设置
安装
使用 pip 从 PyPI 或 GitHub 直接安装最新版:

# 或从 GitHub 安装开发版 pip install git+https://github.com/OpenClaw/OpenClawCLI.git
快速配置(首次使用)
安装后,运行初始化命令,按提示交互式地配置你常用的AI服务API密钥。
openclaw config setup
你将被引导输入 OpenAI、DeepSeek、智谱AI等服务的API Key,这些信息会被安全地保存在本地配置文件中。
主要使用方法
OpenClawCLI 采用 openclaw <模块> <子命令> [参数] 的命令结构。
对话模块
最常用的功能,与AI模型进行交互式对话或单次问答。
- 交互式对话(类似 ChatGPT):
openclaw chat # 默认使用预设模型,开始多轮对话,输入 ‘exit’ 或 ‘quit’ 退出。
- 指定模型对话:
openclaw chat --model deepseek-chat # 使用 DeepSeek 模型进行对话
- 单次问答(非交互式):
openclaw chat --prompt "请用Python写一个快速排序函数" # 直接提问并获取答案后退出
图像生成模块
使用文生图模型(如 DALL-E、DeepSeek-Vision)创建图像。
- 生成图像:
openclaw image create "一只戴着侦探帽的橘猫,蒸汽朋克风格" # 根据描述生成图像,图片将保存到当前目录
- 指定参数:
openclaw image create "星空下的城堡" --size 1024x1024 --num 2 # 生成指定尺寸和数量的图片
配置管理模块
管理你的API密钥和默认设置。
- 查看当前配置:
openclaw config list # 显示已配置的所有服务密钥(密钥部分会隐藏)
- 设置/修改某个服务的API密钥:
openclaw config set --service openai --api-key sk-your-actual-key-here
- 设置默认模型:
openclaw config set --default-model deepseek-chat
模型列表模块
查看所有支持可用的AI模型及其标识符。
openclaw list models # 显示完整的模型列表,包括名称、提供商和简要描述
系统状态检查
检查工具的健康状况和配置连通性。
openclaw health # 验证配置是否正确,API端点是否可达
高级用法与技巧
使用环境变量(更安全)
为避免在命令历史中留下密钥,建议使用环境变量:
# 在终端中设置(临时) export OPENAI_API_KEY='sk-your-key' # 然后运行命令,CLI会优先使用环境变量 openclaw chat --model gpt-4o
可以将 export 命令添加到你的 shell 配置文件(如 ~/.bashrc 或 ~/.zshrc)中永久设置。
使用配置文件
所有配置默认保存在 ~/.openclaw/config.yaml,你也可以手动编辑此文件,或使用 openclaw config 命令管理。
在脚本中使用
OpenClawCLI 的输出可以轻松嵌入到Shell脚本或自动化流程中:
# 获取AI回答并存入变量 RESPONSE=$(openclaw chat --model qwen-plus --prompt "一句话总结量子计算" --no-stream) echo "AI回答:$RESPONSE"
获取帮助
随时使用 --help 参数查看详细帮助:
# 查看全局帮助 openclaw --help # 查看特定模块(如chat)的帮助 openclaw chat --help # 查看子命令(如image create)的帮助 openclaw image create --help
常用命令速查表
| 命令 | 功能 | 示例 |
|---|---|---|
openclaw chat |
进入交互式对话 | openclaw chat |
openclaw chat --prompt |
单次提问 | openclaw chat -p "你好" |
openclaw chat --model |
指定模型聊天 | openclaw chat -m glm-4 |
openclaw image create |
生成图像 | openclaw image create "画面描述" |
openclaw config list |
查看配置 | openclaw config list |
openclaw config setup |
交互式配置 | openclaw config setup |
openclaw list models |
列出模型 | openclaw list models |
openclaw health |
检查状态 | openclaw health |
AI小龙虾OpenClawCLI 的核心是 openclaw chat 和 openclaw image create 这两个最常用的命令,通过 openclaw config setup 完成首次配置后,你就可以轻松地在命令行中调用强大的AI能力了。
对于更复杂的用法,请随时查阅内置的 --help 文档或访问项目的官方 GitHub 仓库。