> ## Documentation Index
> Fetch the complete documentation index at: https://docs.autodl.art/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenClaw

> 使用 AutoDL 第三方 Token 配置 OpenClaw

OpenClaw 是一个可扩展的 AI Agent 网关。通过配置 AutoDL 的 OpenAI 兼容接口，你可以让 OpenClaw 使用 AutoDL 提供的大模型。

## 前置准备

1. 安装 Node.js 和 npm。
2. 前往「大模型」->「[令牌管理](https://www.autodl.art/large-model/tokens)」创建并复制 `API_KEY`。
3. 前往「[大模型](https://www.autodl.art/large-model/market)」页面复制要使用的模型名称。

> [!NOTE]
>
> 下方配置中的 `<你的API_KEY>` 和 `<模型名称>` 需要替换为 AutoDL 页面中的实际值。

## 安装 OpenClaw

### Windows

在 PowerShell 中执行：

```PowerShell theme={null}
iwr -useb https://openclaw.ai/install.ps1 | iex
```

### Linux 和 macOS

在终端中执行：

```Shell theme={null}
curl -fsSL https://openclaw.ai/install.sh | bash
```

安装完成后，检查 OpenClaw 是否可用：

```Shell theme={null}
openclaw --version
```

## 配置 AutoDL Token

为了避免把 Token 直接写入配置文件，建议先将 Token 保存为环境变量。

### Windows

在 PowerShell 中执行以下命令，本次终端会话立即生效：

```PowerShell theme={null}
$env:AUTODL_API_KEY="<你的API_KEY>"
```

如果希望永久保存，可以执行：

```PowerShell theme={null}
setx AUTODL_API_KEY "<你的API_KEY>"
```

执行 `setx` 后，关闭当前终端并重新打开。

### Linux

在终端中执行：

```Shell theme={null}
export AUTODL_API_KEY="<你的API_KEY>"
```

如果希望永久生效，可以写入 `~/.bashrc`：

```Shell theme={null}
echo 'export AUTODL_API_KEY="<你的API_KEY>"' >> ~/.bashrc
source ~/.bashrc
```

如果使用 Zsh，将 `~/.bashrc` 替换为 `~/.zshrc`。

### macOS

macOS 默认使用 Zsh，可以写入 `~/.zshrc`：

```Shell theme={null}
echo 'export AUTODL_API_KEY="<你的API_KEY>"' >> ~/.zshrc
source ~/.zshrc
```

如果只希望临时使用，可以直接执行：

```Shell theme={null}
export AUTODL_API_KEY="<你的API_KEY>"
```

## 配置模型提供商

OpenClaw 的配置文件通常位于以下路径：

```text theme={null}
Windows: %USERPROFILE%\.openclaw\openclaw.json
Linux:   ~/.openclaw/openclaw.json
macOS:   ~/.openclaw/openclaw.json
```

如果配置文件不存在，可以先运行：

```Shell theme={null}
openclaw onboard
```

然后打开 `openclaw.json`，在配置文件中加入以下内容：

```json5 theme={null}
{
  models: {
    mode: "merge",
    providers: {
      autodl: {
        baseUrl: "https://www.autodl.art/api/v1",
        apiKey: "${AUTODL_API_KEY}",
        api: "openai-completions",
        models: [
          {
            id: "<模型名称>",
            name: "<模型名称>",
          },
        ],
      },
    },
  },
  agents: {
    defaults: {
      model: {
        primary: "autodl/<模型名称>",
      },
    },
  },
}
```

> [!WARNING]
>
> `<模型名称>` 必须替换为 AutoDL「大模型」页面中的完整模型名称，并且 `primary` 中的名称要与 `models` 数组中的 `id` 保持一致。

### 配置项说明

| 配置项 | 说明 |
| - | - |
| `autodl` | 自定义服务商名称，可以按需修改 |
| `baseUrl` | AutoDL OpenAI 兼容接口地址 |
| `apiKey` | 从环境变量读取 AutoDL Token |
| `api` | 使用 OpenAI Chat Completions 兼容协议 |
| `models[].id` | AutoDL 大模型页面中的模型名称 |
| `agents.defaults.model.primary` | OpenClaw 默认使用的模型，格式为 `服务商/模型名称` |

## 启动 OpenClaw

保存配置后，重新打开终端并运行：

```Shell theme={null}
openclaw gateway
```

如果希望 OpenClaw 在后台运行，可以按照 OpenClaw 官方文档配置 Gateway 服务。

## 验证配置

1. 确认 `openclaw gateway` 已正常启动。
2. 打开 OpenClaw 已配置的聊天入口。
3. 发送一条简单消息，例如：`请介绍一下你自己`。
4. 如果模型能够正常返回回答，说明 AutoDL Token 和模型配置成功。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.