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

本指南将使你能够在本地使用开源 LLM， **通过将 OpenClaw 连接到 Unsloth**。OpenClaw 是一个 **开源 AI 智能体** 界面，它连接到模型以在你的项目中执行任务。

OpenClaw 通过连接 **Unsloth 的 OpenAI 兼容 API**，能够与任何本地模型配合使用：包括 DeepSeek、Qwen、Gemma 等。OpenClaw 充当客户端，而 Unsloth 通过一个 **本地 API**.

进行加载和提供模型服务。设置完成后，OpenClaw 将通过 Unsloth 在你的本地模型上运行，让你可以直接将其用作 **AI 智能体。**

<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 %}

{% hint style="info" %}
API 访问包含在 **Unsloth（Beta）**&#x4E2D;。请确保你使用的是最新版本，较早的构建版本不会暴露外部 API。请参阅安装以进行安装或更新。
{% endhint %}

### 安装 Unsloth

### ⚡ 快速开始

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

1. **安装或更新** [**Unsloth Studio**](/docs/zh/xin/studio.md)**.** 较早版本不会暴露外部 API。请参阅安装。
2. **启动 Unsloth。** 请注意，它启动时的端口通常是 `8000` 或 `8888`。你会在终端输出和浏览器 URL（`http://localhost:PORT`).
3. **）中看到它。加载一个模型。** 点击 **新聊天**，选择或搜索一个模型（GGUF），并等待其完成加载。
4. **创建一个 API 密钥。** 在 Unsloth 中，点击左下角的 **Unsloth** 头像 → **设置** → **API 密钥** → 输入密钥名称 → **创建**。复制出现的 `sk-unsloth-…` 值。Unsloth 只会显示一次。
5. **将你的客户端指向 Unsloth。** 使用 `http://localhost:PORT` 作为基础 URL，并使用你的 `sk-unsloth-…` 密钥进行身份验证。请直接跳转到下面适用于你工具的配方。

### 🔑 创建 API 密钥

密钥可从 **Unsloth → 设置 → API 密钥**.

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

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

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

{% hint style="warning" %}
请像对待密码一样对待你的 API 密钥。任何拥有该密钥且能访问你的 Unsloth 实例网络的人，都可以向你已加载的模型发送请求。
{% endhint %}

### 连接到 OpenClaw

OpenClaw 从以下位置读取其配置： `~/.openclaw/openclaw.json`。添加（或合并）一个带有 `models` 块的 `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/v1",
        "apiKey": "sk-unsloth-xxxxxxxxxxxx",
        "api": "anthropic-messages",
        "models": [
          {
            "id": "unsloth/Qwen3.6-27B-GGUF",
            "name": "unsloth/Qwen3.6-27B-GGUF"
          }
        ],
        "authHeader": true
      }
    }
  }
}
```

{% endcode %}

**说明：**

* `baseUrl` 必须以 `/v1`.
* `api: "anthropic-messages"` 告诉 OpenClaw 与 Unsloth 的 `/v1/messages` 端点通信。
* `authHeader: true` 会将你的密钥作为 `Authorization: Bearer …`.
* 设置每个模型的 `id` 和 `name` 为你在 Unsloth 中加载模型时选择的名称。
* 如果你在远程机器上运行 Unsloth，请将 `localhost:8888` 替换为那台机器的地址（例如 `http://10.0.0.42:8888/v1`).


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
