> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/zh/ji-cheng/openclaw.md).

# 如何使用 OpenClaw 运行本地 AI 模型

本指南将展示如何将本地运行的开源大语言模型与 **OpenClaw 通过连接到 Unsloth 来使用**。OpenClaw 是一个 **开源 AI 代理** 接口，它连接到一个模型，以在你的项目中运行任务。OpenClaw 通过连接 **Unsloth 的 OpenAI 兼容 API**即可与任何本地模型协同工作：包括 DeepSeek、Qwen、Gemma 等。

OpenClaw 充当客户端，而 Unsloth 通过一个 **本地 API**提供和加载模型。设置完成后，OpenClaw 将通过 Unsloth 针对你的本地模型运行，让你可以直接将其用作 **AI 代理。** 在本教程中，我们将使用 [Qwen3.6](/docs/zh/mo-xing/qwen3.6.md).

<a href="/pages/f1eb04d9bdae8f6dbb3d9ed5d64e060dac5a68ff#connecting-to-openclaw" class="button primary" data-icon="lobster">连接到 OpenClaw</a><a href="/pages/f1eb04d9bdae8f6dbb3d9ed5d64e060dac5a68ff#quickstart" class="button primary">快速入门</a>

{% hint style="info" %}
&#x20;在本教程中，我们将使用 `unsloth/Qwen3.6-27B-GGUF` 在 Unsloth 中并通过 OpenClaw 访问它。想用别的模型？只需在 Unsloth 中加载其他模型并更新配置即可。
{% endhint %}

### 安装 OpenClaw

{% tabs %}
{% tab title="macOS、Linux、WSL" %}
使用官方安装程序安装 OpenClaw：

`curl -fsSL https://openclaw.ai/install.sh | bash`

这会设置 OpenClaw，并引导你完成初始配置。
{% endtab %}

{% tab title="Windows（PowerShell）" %}
使用官方安装程序安装 OpenClaw：

`iwr -useb https://openclaw.ai/install.ps1 | iex`

这会设置 OpenClaw，并引导你完成初始配置。
{% endtab %}
{% endtabs %}

### ⚡ 快速开始

安装 OpenClaw 后，我们还需要安装 Unsloth Studio，以便让 OpenClaw 能够提供本地模型并运行推理。

1. **安装或更新** [**Unsloth Studio**](/docs/zh/xin-de/studio.md)**.** 较早版本不暴露外部 API。参见安装。
2. **启动 Unsloth。** 注意它启动时使用的端口通常是 `8000` 或 `8888`。你会在终端输出以及浏览器 URL 中看到它（`http://localhost:PORT`).
3. **加载模型。** 点击 **新建聊天**，选择或搜索一个模型（GGUF），并等待其加载完成。
4. **连接 OpenClaw。** 运行 `unsloth start openclaw` 以在一个独立的受管环境中，用已加载的 Unsloth 模型启动 OpenClaw。你正常的 OpenClaw 配置不会被更改。

### ⚙️ 使用 `unsloth start`

OpenClaw 可以连接到已经在 Unsloth Studio 中运行的模型，也可以在 Unsloth 未运行时自动启动一个。

连接到正在运行的 Unsloth 实例

一旦模型在 Unsloth Studio 中加载完成，运行：

```bash
unsloth start openclaw
```

<div data-with-frame="true"><figure><img src="/files/0abd61215352f1c2a13a2e6492977d86001d447d" alt="" width="563"><figcaption></figcaption></figure></div>

Unsloth 会在一个独立的受管环境中，以已配置好的 Unsloth 提供方、模型和上下文长度，在本地 TUI 模式下启动 OpenClaw。你正常的 OpenClaw 设置不会被更改。

一旦 OpenClaw 打开，给它一个任务，例如：

```
检查这个仓库，并用一句话总结它：https://github.com/unslothai/unsloth
```

<div data-with-frame="true"><figure><img src="/files/4defbb838bc6e38c461e77d37b3523e70af43ee2" alt="" width="563"><figcaption></figcaption></figure></div>

#### 自动启动模型

如果 Unsloth Studio 尚未运行，请传入一个模型 ID：

```bash
unsloth start openclaw --model unsloth/Qwen3.6-27B-GGUF
```

Unsloth 会启动模型、启动 OpenClaw，并在你退出时停止临时服务器。\
\
要保留你的 OpenClaw 状态并在之后返回到同一会话，请添加 `--persist` 并选择一个会话键：

```bash
unsloth start openclaw \
  --model unsloth/Qwen3.6-27B-GGUF \
  --persist \
  agent --local \
  --session-key my-session \
  --message "Inspect this repository"
```

稍后使用相同的会话键继续：

```bash
unsloth start openclaw \
  --model unsloth/Qwen3.6-27B-GGUF \
  --persist \
  agent --local \
  --session-key my-session \
  --message "Continue"
```

查看完整的 [unsloth start](/docs/zh/ji-cheng/unsloth-start.md) 有关命名会话、模型加载、远程 Unsloth 服务器以及高级选项的参考。

本指南的其余部分将介绍手动配置 OpenClaw 提供方。

### 手动配置 OpenClaw 提供方

### 🔑 创建 API 密钥

密钥可从以下位置创建： **Unsloth → 设置 → API 密钥**.

1. 打开侧边栏，点击左下角的 **Unsloth** 头像。
2. 前往 **设置** → **API 密钥**.
3. 输入一个友好的名称（例如 `claude-code-macbook`).
4. *（可选）* 设置过期时间。
5. 点击 **创建**.
6. **立即复制该密钥。** Unsloth 只存储哈希值，你将无法再次查看它。

<div data-with-frame="true"><figure><img src="/files/3432517ab3e4dadf17eb7ea5f319b43cc5902dd2" alt="" width="375"><figcaption></figcaption></figure></div>

所有密钥都以 `sk-unsloth-` 前缀开头。你可以随时在同一页面撤销密钥。使用已撤销密钥发出的请求将失败，并返回 `401 未授权`.

### 连接到 OpenClaw

OpenClaw 从以下位置读取其配置： `~/.openclaw/openclaw.json`。添加（或合并）一个 `比较` 块，其中包含一个 `unsloth` 指向 Unsloth 的 Anthropic Messages API 的提供方。

<div data-with-frame="true"><figure><img src="/files/07ec4a323098a7644fbd73ef89c4ef9df3c3f5de" alt="" width="375"><figcaption></figcaption></figure></div>

{% code title="\~/.openclaw/openclaw\.json" %}

```json
{
  "models": {
    "mode": "merge",
    "providers": {
      "unsloth": {
        "baseUrl": "http://localhost:8888",
        "apiKey": "sk-unsloth-xxxxxxxxxxxx",
        "api": "anthropic-messages",
        "models": [
          {
            "id": "unsloth/Qwen3.6-27B-GGUF",
            "name": "unsloth/Qwen3.6-27B-GGUF"
          }
        ],
        "authHeader": true
      }
    }
  }
}
```

{% endcode %}

**注意：**

* `baseUrl` 是不带路径的 Unsloth 源地址。OpenClaw 通过 Anthropic Messages API 与 Unsloth 通信，而 Anthropic SDK 会自行附加 `/v1/messages` ，所以不要在这里添加 `/v1` （末尾的 `/v1` 会把请求发送到 `/v1/v1/messages`).
* `api: "anthropic-messages"` 会告诉 OpenClaw 与 Unsloth 的 `/v1/messages` 端点通信。
* `authHeader: true` 将你的密钥作为 `Authorization: Bearer …`.
* 将每个模型的 `id` 和 `name` 设置为你在 Unsloth 中加载模型时选择的名称。
* 如果你在远程机器上运行 Unsloth，请将 `localhost:8888` 替换为那台机器的地址（例如 `http://10.0.0.42:8888`).

### 可选：配置模型行为

OpenClaw 通过在 Unsloth 中运行的模型进行连接。启动服务器时可以配置运行时设置。

```bash
# 配置默认生成行为（--disable-tools 会透传 OpenClaw 自己的工具）
unsloth run \\
  --model unsloth/gemma-4-26B-A4B-it-GGUF \
  --disable-tools \
  --reasoning off \
  --temp 0.6
```

{% hint style="warning" %}
使用 `--disable-tools` 在驱动 OpenClaw（或任何外部编码代理）时。默认情况下，Unsloth Studio 会运行自己的服务器端工具，这会吞掉代理的工具调用，因此 OpenClaw 会给出回答，但从不编辑文件。 `--disable-tools` 切换为直通模式，因此会使用 OpenClaw 自己的工具。
{% endhint %}

使用 `--reasoning off` 用于关闭思考，或 `--reasoning on` 用于在支持推理的模型上开启它。

```bash
# 允许来自其他设备的连接
unsloth run \\
  --model unsloth/gemma-4-26B-A4B-it-GGUF \
  -H 0.0.0.0 \\
  -p 8888
```

这会在 `0.0.0.0:8888`上启动服务器，允许本地网络中的其他设备连接。

有关更高级的运行时配置，请参阅主 [API 调优](https://unsloth.ai/docs/basics/api#unsloth-run-command) 部分。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://unsloth.ai/docs/zh/ji-cheng/openclaw.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
