指南

CLI 自动化

使用 openclaw onboard --non-interactive 编写设置脚本。它需要 --accept-risk:非交互式设置无需确认提示即可写入凭据和守护进程配置,因此该标志表示明确确认风险。

非交互式基准示例

bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice apiKey \  --anthropic-api-key "$ANTHROPIC_API_KEY" \  --secret-input-mode plaintext \  --gateway-bind loopback \  --install-daemon \  --daemon-runtime node \  --skip-bootstrap \  --skip-skills

添加 --json 可获得机器可读的摘要。

  • --gateway-port 默认为 18789;仅在需要覆盖时传入。
  • --skip-bootstrap 会跳过创建默认工作区文件,适用于预先填充自有工作区的自动化流程。
  • --secret-input-mode ref 会在身份验证配置文件中存储由环境变量支持的引用({ source: "env", provider: "default", id: "<ENV_VAR>" }),而非明文密钥。在非交互式 ref 模式下,提供商环境变量必须已在进程环境中设置:如果传入内联密钥标志,但未设置对应的环境变量,操作会立即失败。
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice openai-api-key \  --secret-input-mode ref

提供商专用示例

Anthropic API 密钥示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice apiKey \  --anthropic-api-key "$ANTHROPIC_API_KEY" \  --gateway-bind loopback
Cloudflare AI Gateway 示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice cloudflare-ai-gateway-api-key \  --cloudflare-ai-gateway-account-id "your-account-id" \  --cloudflare-ai-gateway-gateway-id "your-gateway-id" \  --cloudflare-ai-gateway-api-key "$CLOUDFLARE_AI_GATEWAY_API_KEY" \  --gateway-bind loopback
Gemini 示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice gemini-api-key \  --gemini-api-key "$GEMINI_API_KEY" \  --gateway-bind loopback
Mistral 示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice mistral-api-key \  --mistral-api-key "$MISTRAL_API_KEY" \  --gateway-bind loopback
Moonshot 示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice moonshot-api-key \  --moonshot-api-key "$MOONSHOT_API_KEY" \  --gateway-bind loopback
Ollama 示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice ollama \  --custom-model-id "qwen3.5:27b" \  --gateway-bind loopback
OpenCode 示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice opencode-zen \  --opencode-zen-api-key "$OPENCODE_API_KEY" \  --gateway-bind loopback

对于 Go 目录,请改用 --auth-choice opencode-go --opencode-go-api-key "$OPENCODE_API_KEY"

Synthetic 示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice synthetic-api-key \  --synthetic-api-key "$SYNTHETIC_API_KEY" \  --gateway-bind loopback
Vercel AI Gateway 示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice ai-gateway-api-key \  --ai-gateway-api-key "$AI_GATEWAY_API_KEY" \  --gateway-bind loopback
Z.AI 示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice zai-api-key \  --zai-api-key "$ZAI_API_KEY" \  --gateway-bind loopback
自定义提供商示例
bash
openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice custom-api-key \  --custom-base-url "https://llm.example.com/v1" \  --custom-model-id "foo-large" \  --custom-api-key "$CUSTOM_API_KEY" \  --custom-provider-id "my-custom" \  --custom-compatibility anthropic \  --custom-image-input \  --gateway-bind loopback

--custom-api-key 是可选项;部分端点不需要身份验证。如果省略,新手引导会检查环境变量中的 CUSTOM_API_KEY--custom-provider-id 是可选项,省略时会根据基础 URL 自动派生。--custom-compatibility 默认为 openai(其他值:openai-responsesanthropic)。

OpenClaw 会根据已知的视觉模型 ID 模式(gpt-4oclaude-3/4gemini-vl/vision 后缀以及类似模式)推断图像输入支持。对于无法识别的视觉模型,添加 --custom-image-input 可强制启用该功能,添加 --custom-text-input 则可强制仅使用文本。

引用模式变体,将 apiKey 存储为 { source: "env", provider: "default", id: "CUSTOM_API_KEY" }

bash
export CUSTOM_API_KEY="your-key"openclaw onboard --non-interactive --accept-risk \  --mode local \  --auth-choice custom-api-key \  --custom-base-url "https://llm.example.com/v1" \  --custom-model-id "foo-large" \  --secret-input-mode ref \  --custom-provider-id "my-custom" \  --custom-compatibility anthropic \  --custom-image-input \  --gateway-bind loopback

仍支持 Anthropic 设置令牌身份验证,但如果本地 Claude CLI 已登录,OpenClaw 会优先复用 Claude CLI。生产环境中,优先使用 Anthropic API 密钥。

添加另一个智能体

openclaw agents add <name> 会创建一个单独的智能体,该智能体拥有自己的工作区、会话和身份验证配置文件。不带 --workspace(且不带其他标志)运行该命令会启动交互式向导;传入 --workspace--model--agent-dir--bind--non-interactive 中的任意一个会以非交互方式运行,此时还需要 --workspace

bash
openclaw agents add work \  --workspace ~/.openclaw/workspace-work \  --model openai/gpt-5.6-sol \  --bind whatsapp:biz \  --non-interactive \  --json

它会写入以下配置键(新智能体 ID 的 agents.entries.* 条目):

  • name
  • workspace
  • agentDir
  • model(仅在传入 --model 时)

注意:

  • 默认工作区(在交互式向导中省略 --workspace 时):~/.openclaw/workspace-<agentId>
  • --bind <channel[:accountId]> 可重复使用;添加绑定可将入站消息路由到新智能体(也可通过向导以交互方式完成)。
  • 智能体名称会规范化为有效的智能体 ID;main 为保留值。

相关文档

Was this useful?
On this page

On this page