Skip to content

OpenClaw 配置

OpenClaw(曾用名 Clawdbot / Moltbot)把「定义供应商」和「允许使用的模型」分成两步。只加 provider、不加 allowlist,会出现 model not allowed

官方:https://docs.openclaw.ai/concepts/model-providers
安装:npm install -g openclaw
配置文件:~/.openclaw/openclaw.json(旧路径 ~/.clawdbot/clawdbot.json 会自动软链)

图形界面 = Control UI → Settings → Model Providers。命令行 = openclaw onboard / openclaw models … / 手改 JSON。

快速字段

Provider idashpetals(自拟,小写)
baseUrlhttps://api.ashpetals.com/v1
apiopenai-completions(Chat);Claude 可用 anthropic-messages 且 baseUrl 不带 /v1
apiKeysk-你的APIKey
模型 id/v1/models 完全一致,例如 gpt-5.6-sol
引用格式ashpetals/gpt-5.6-solprovider/model
allowlistagents.defaults.models 里必须有这条全名

图形界面(Control UI)

  1. 打开 OpenClaw Control UI。
  2. Settings → Model Providers
  3. 添加自定义供应商:
    • Provider ID:ashpetals
    • Base URL:https://api.ashpetals.com/v1
    • API type:OpenAI Completions / openai-completions
    • API Key:sk-你的APIKey(页面保存后只显示脱敏,密钥来自配置或环境变量)
  4. 在模型目录里添加至少一条,id = gpt-5.6-sol(或点 Test connection 探测)。
  5. Default models 卡片:把 primary 设为 ashpetals/gpt-5.6-sol 并保存。这一步会写入 agents.defaults.model,相当于 allowlist。
  6. Test connection 会发真实请求、消耗少量 token。

添加 / 重新登录供应商 不会自动改你当前的 primary。要换默认模型必须在 Default models 里保存,或用下面的 CLI models set

CC Switch 桌面

顶部选 OpenClaw,按 OpenAI 兼容填 https://api.ashpetals.com/v1。导入后仍建议打开 Control UI 确认 allowlist 里有 ashpetals/<model>


命令行 / 配置文件

CLI 向导

bash
openclaw onboard
openclaw configure
openclaw models list
openclaw models set ashpetals/gpt-5.6-sol

openclaw models auth login 默认也不改 primary,除非加 --set-default

手写 openclaw.json(完整最小例)

两处都要改:models.providers agents.defaults.models

json
{
  "models": {
    "mode": "merge",
    "providers": {
      "ashpetals": {
        "baseUrl": "https://api.ashpetals.com/v1",
        "apiKey": "sk-你的APIKey",
        "api": "openai-completions",
        "models": [
          {
            "id": "gpt-5.6-sol",
            "name": "GPT-5.6 Sol",
            "reasoning": true,
            "input": ["text"],
            "contextWindow": 272000,
            "maxTokens": 16384
          },
          {
            "id": "deepseek-v4-flash",
            "name": "DeepSeek V4 Flash",
            "reasoning": true,
            "input": ["text"],
            "contextWindow": 128000,
            "maxTokens": 8192
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "models": {
        "ashpetals/gpt-5.6-sol": { "alias": "sol" },
        "ashpetals/deepseek-v4-flash": { "alias": "dsflash" }
      },
      "model": {
        "primary": "ashpetals/gpt-5.6-sol"
      }
    }
  }
}

Claude 分组示例(另建 provider,避免和 Chat 抢同一个 baseUrl):

json
"ashpetals-claude": {
  "baseUrl": "https://api.ashpetals.com",
  "apiKey": "sk-你的APIKey",
  "api": "anthropic-messages",
  "models": [
    {
      "id": "claude-sonnet-5",
      "name": "Claude Sonnet 5",
      "input": ["text"],
      "contextWindow": 200000,
      "maxTokens": 8192
    }
  ]
}

allowlist key 写成 ashpetals-claude/claude-sonnet-5

应用配置

bash
openclaw gateway config.apply --file ~/.openclaw/openclaw.json

网关会重载。会话里:

/models
/model sol
/status

CC-Switch CLI

bash
cc-switch --app openclaw provider add
cc-switch --app openclaw provider list
cc-switch --app openclaw provider switch <id>

导入后仍建议 openclaw models list 确认全名已在 allowlist。


验证

bash
openclaw models list
openclaw models set ashpetals/gpt-5.6-sol

Control UI 里对该供应商点 Test connection。

bash
curl -sS https://api.ashpetals.com/v1/chat/completions \
  -H "Authorization: Bearer sk-你的APIKey" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-5.6-sol","messages":[{"role":"user","content":"ping"}]}'

常见问题

Q: model not allowed: ashpetals/gpt-5.6-sol
A: 只写了 provider,没写 agents.defaults.models。allowlist 的 key 必须是 全名 provider/id,不是裸 gpt-5.6-sol

Q: /models 里没有
A: models.providers.ashpetals.models[] 缺这条,或没 config.apply / 没重启网关。

Q: 打到了错误模型
A: models[].id 必须等于本站 /v1/models 的 id。OpenClaw 内部全名不会发给上游,上游只看到 id

Q: 加了 Key,默认模型没变
A: 设计如此。用 openclaw models set … 或 Default models 卡片保存。

Q: JSON 解析失败
A: 缺逗号 / 尾逗号。可让 OpenClaw 自己修配置,或用 python3 -m json.tool ~/.openclaw/openclaw.json


注意事项

  • Chat 用 openai-completions + /v1;Claude 用 anthropic-messages + 根地址。
  • cost 字段只做用量估算,不是本站账单。本站账单以控制台为准。
  • Key 也可走环境变量(<PROVIDER>_API_KEY)。不要把 JSON 提交到 Git。
  • 旧命令 clawdbot 仍可能是别名;新安装用 openclaw

AshPetals API — 单主站 · OpenAI 兼容