> 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-chu-zhi-shi/api.md).

# 如何将 Unsloth 用作 API 端点

你可以运行 **本地 LLM** 配合以下工具： [Claude Code](/docs/zh/ji-chu-zhi-shi/claude-code.md) 和 [Codex](/docs/zh/ji-chu-zhi-shi/codex.md) ，方法是将这些工具连接到 Unsloth 的 **与 OpenAI 兼容的 API 端点**。这使你可以本地运行诸如 [Qwen](/docs/zh/mo-xing/qwen3.6.md) 和 [Gemma](/docs/zh/mo-xing/gemma-4.md) 之类的模型，用于代理式编码。Unsloth 还具备诸如自修复 **工具调用**, **代码执行**，以及 **网络搜索**.

Unsloth 可轻松部署一个高速 API 推理端点，提供：

* [**自修复工具调用**](/docs/zh/xin/studio/chat.md#auto-healing-tool-calling)，可帮助将损坏或格式错误的工具调用减少 50%
* [**代码执行**](/docs/zh/xin/studio/chat.md#code-execution) 支持，允许执行 Bash 和 Python，以获得更准确的代码输出。
* **高级** [**网络搜索**](/docs/zh/xin/studio/chat.md#advanced-web-search) ，会访问并实际读取网页，以收集深入信息。
* [**自动推理** 设置](/docs/zh/xin/studio/chat.md#auto-parameter-tuning) 适用于 GGUF 模型（temp、top-k 等）

{% columns %}
{% column %}
在 Unsloth 中加载的模型（包括 GGUF）会以 **经过身份验证的 API** 通过 `llama-server` 的形式暴露。出于安全原因，会生成一个较长的 API 密钥，就像 OpenAI 提供的一样。

你的 **本地模型** 随后可以直接在你首选的 AI 代理、SDK 或聊天客户端中使用。Unsloth 在同一个端口上支持两种接口风格。二者都支持流式传输、工具调用（OpenAI `工具` / Anthropic `工具`），以及视觉输入：
{% endcolumn %}

{% column %}

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FgCthbL3uUmrNgxFBePK5%2Fimage.png?alt=media&amp;token=060dbc41-6fd5-496d-ba00-0ba13fde86ff" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

无论你的模型是通过 Unsloth 的推理运行，还是通过你自己的远程 OpenAI 兼容端点运行，你都可以让它使用 Unsloth 的完整工具套件，包括网络搜索、代码执行、深度研究等。

* **与 Anthropic 兼容的 `/v1/messages`**  ，适用于 Claude Code、OpenClaw、Anthropic SDK，以及任何期望 Messages API 的客户端。
* **与 OpenAI 兼容的 `/v1/chat/completions`** 和 **`/v1/responses`** ，适用于 OpenAI SDK、OpenCode、Cursor、Continue、Cline、Open WebUI、SillyTavern，以及任何与 OpenAI 兼容的工具。

### ⚡ 快速开始

{% stepper %}
{% step %}

#### 下载 Unsloth

最简单的开始方式是安装 [Unsloth Desktop](/docs/zh/desktop.md) 应用程序。它支持 [MacOS](/docs/zh/kuai-su-kai-shi/install/mac.md)、Linux、 [Windows](/docs/zh/kuai-su-kai-shi/install/windows-installation.md), [NVIDIA](/docs/zh/kuai-su-kai-shi/install/pip-install.md), [AMD](/docs/zh/kuai-su-kai-shi/install/amd.md)、Intel 和 CPU 配置。

<a href="https://unsloth.ai/download" class="button primary" data-icon="down-to-bracket">下载 Unsloth</a>

* <i class="fa-apple">:apple:</i> [下载 macOS 版](https://unsloth.ai/download/mac)
* <i class="fa-windows">:windows:</i> [下载 Windows 版](https://unsloth.ai/download/windows)
* <i class="fa-linux">:linux:</i> [下载 Linux 版](https://unsloth.ai/download/linux)

或者，如果你更喜欢手动安装：

**MacOS、Linux、WSL：**

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

**Windows PowerShell：**

```bash
irm https://unsloth.ai/install.ps1 | iex
```

{% endstep %}

{% step %}

#### 安装

1. 打开 Unsloth 安装程序（`.dmg`, `.exe` 文件）
2. 将 Unsloth 拖到 Mac 的 Applications，或完成 Windows 设置。
3. 启动应用并等待安装完成
   {% endstep %}

{% step %}

#### 选择模型

打开顶部的“选择模型”下拉菜单或“模型中心”标签，选择适合你设备的模型和量化方式，然后下载。完成后即可开始聊天——无需额外设置。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FNCEVgKLJI0goPqjgcg9B%2Fmodel%20hub%20models.png?alt=media&amp;token=533b5e3c-a901-4b33-963e-4a703cc9d5a6" alt="" width="563"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Unsloth 现已就绪

要开始聊天，请输入消息并按 Enter。

* **创建 API 密钥。** 点击左下角你的 **Unsloth** 头像 → **设置** → **API** → 输入密钥名称 → **创建**。复制 `sk-unsloth-…` 显示的值。Unsloth 只会显示一次。
* **将你的客户端指向 Unsloth。** 使用 `http://localhost:PORT` 作为基础 URL，并使用你的 `sk-unsloth-…` 密钥进行身份验证。下面直接跳到你的工具对应的示例。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FpAGvwjGD0iVMZKBoyu7m%2Fgreeennn.png?alt=media&amp;token=d17a5528-8375-444c-9aff-f9e9f7903bcd" alt="" width="563"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### 🔑 创建 API 密钥

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

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FR7fhygHCl5RwG4P1MSoS%2Fimage.png?alt=media&amp;token=e2781a00-7fe5-4831-9fdb-a57234843b34" alt="" width="563"><figcaption></figcaption></figure></div>

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

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

### ⏳ 模型加载

{% stepper %}
{% step %}

#### 选择模型

在使用 API 之前，请从 Chat 页面左上角的 **选择模型** 下拉菜单中加载一个模型。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FuZqd6tcZ5LgMSh4ZND5x%2Fexport-1778505117710-24fps.gif?alt=media&amp;token=9defec95-5404-4654-9c33-67be967c9820" alt=""><figcaption></figcaption></figure>

本指南中，我们将使用：

`unsloth/gemma-4-26B-A4B-it-GGUF` 并使用推荐的 `UD-Q4_K_XL` 量化。
{% endstep %}

{% step %}

#### 测试模型

在使用客户端之前，请先发送一条简短消息：

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F2Ivilke0aJX8AHWDwSmr%2Fimage.png?alt=media&amp;token=9f9380b9-f963-4861-a17b-fd0fe16684d4" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="info" %}
这可以确认模型已正确加载并准备好响应。
{% endhint %}
{% endstep %}

{% step %}

#### **Unsloth API 密钥**

在 Unsloth 中，打开 **设置 → API** 以查看或创建你的 API 密钥。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FAZwaRmBVPpXA2SFhMGW9%2Fexport-1778506924396-30fps.gif?alt=media&amp;token=96f3f1a7-fce4-4508-b1b0-e8b6294dc423" alt=""><figcaption></figcaption></figure>

请像对待密码一样对待你的 API 密钥，不要在截图或代码仓库中暴露它。
{% endstep %}
{% endstepper %}

### <i class="fa-terminal">:terminal:</i> Unsloth 运行命令

1. **安装或更新 Unsloth Studio。** 较早版本不暴露外部 API。请参见安装。
2. **加载 GGUF 模型。** 使用运行命令加载 GGUF 模型。这也会在默认端口上加载 UI。端点 URL 和 API 密钥将打印到控制台，供你直接在所选客户端中使用。

   ```bash
   unsloth run --model unsloth/Qwen3.8-27B-GGUF-GGUF:UD-Q4_K_XL
       --temp 1.0 \
       --top-p 0.95 \
       --top-k 20 \
       --min-p 0.0 \
       --chat-template-kwargs '{"reasoning_effort":"medium"}'
   ```

按需调整设置。

#### 从 CLI 加载模型

你可以使用 `unsloth` CLI 工具加载模型，并自动为你创建 API 密钥。模型加载完成后，端点 URL 和 API 密钥会打印到你的控制台。将它们复制到你选择的客户端中即可开始使用。

#### 开始之前

请确保你使用的是较新版本的 Unsloth Studio，因为较早版本不暴露外部 API。参见 [安装](/docs/zh/xin/studio/install.md).

#### 快速方式

打开终端并加载一个 GGUF 模型：

```bash
unsloth run --model unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL
```

这会在默认端口启动服务器、加载 UI，并打印你的端点 URL 和 API 密钥。

#### 模型名称的工作方式

你可以通过几种不同方式指向模型。选择你觉得最方便的一种：

```bash
# 合并：仓库和量化变体写在一个字符串中（推荐——最简短）
unsloth run --model unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL

# 分开：仓库和变体作为两个标志（较旧的风格，仍然可用）
unsloth run --model unsloth/gemma-4-26B-A4B-it-GGUF --gguf-variant UD-Q4_K_XL

# 使用 -hf / --hf-repo（与 llama.cpp 的写法一致，如果你来自那里会很方便）
unsloth run -hf unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL
```

### 调整运行参数（可选）

基础加载不需要这些设置，但 `unsloth run` 支持许多 llama-server 运行时标志，可用于自定义性能、内存使用、上下文长度、生成行为、网络和工具访问。

附加标志会直接传递给底层推理服务器，你设置的值会覆盖 Unsloth 的默认值。如果没有设置任何设置/采样标志，Unsloth 会自动为该模型选择最佳/推荐设置，包括上下文长度、温度等。

#### 控制推理行为

某些具备推理能力的模型支持额外标志，用于控制思考和推理行为。

```bash
# 禁用推理/思考输出
unsloth run \
  --model unsloth/Qwen3.8-27B-GGUF:UD-Q4_K_XL \
  --reasoning on  \
  --reasoning-effort medium
```

推理力度和标志取决于模型支持的内容。

#### 调整生成行为

采样设置控制模型在生成时的创造性、专注度或确定性。

```bash
# 降低随机性并提高可复现性
unsloth run \
  --model unsloth/Qwen3-1.7B-GGUF \
  --temp 0.6 \
  --seed 42
```

较低的温度值通常会产生更稳定的输出，而 top-p、top-k、min-p 和重复惩罚设置则进一步控制 token 选择和重复。

```bash
# 调整 token 选择和重复行为
unsloth run \
  --model unsloth/Qwen3-1.7B-GGUF \
  --top-p 0.95 \
  --top-k 20 \
  --min-p 0.05 \
  --repeat-penalty 1.1
```

#### 增加上下文长度和 CPU 线程数

如果你在处理大型项目、长对话或需要更多内存的代理工作流，这会很有用。

```bash
# 使用更大的上下文窗口和更多 CPU 线程
unsloth run \
  --model unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL \
  -c 131072 \
  --threads 32
```

#### 在你的本地网络上暴露 API

默认情况下，Unsloth 只在你的机器本地运行。你可以通过绑定到以下地址，将 API 暴露给网络中的其他设备： `0.0.0.0`.

```bash
# 允许局域网设备连接
unsloth run \
  --model unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL \
  -H 0.0.0.0 \
  -p 8888
```

#### 启用或禁用服务器端工具

控制推理服务器是否暴露诸如网络搜索和代码执行之类的工具。

```bash
# 明确启用工具
unsloth run \
  --model unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL \
  --enable-tools
```

```bash
# 明确禁用工具
unsloth run \
  --model unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL \
  --disable-tools
```

Unsloth 支持大多数 llama-server 运行时标志，包括上下文大小、GPU 层、线程、采样、网络和工具配置。

请参阅 [llama-server](https://github.com/ggml-org/llama.cpp/tree/master/tools/server) 文档以获取完整的支持运行时标志列表。

#### **服务器端工具策略**

`unsloth run` 控制服务器端工具（网络搜索、代码执行等）是否由推理服务器暴露。默认值取决于绑定地址：

* **`127.0.0.1` （localhost）** — 工具 **开启** ，默认开启。只有你的机器可以访问该服务器。
* **`0.0.0.0` 或任何非回环地址** — 工具 **关闭** ，默认关闭。在网络暴露的服务器上泄露 API 密钥，意味着主机上可执行任意代码。

**标志：**

* `--enable-tools` / `--disable-tools` — 强制开启或关闭。开启时 `0.0.0.0`, `--enable-tools` 会显示一个 y/N 安全提示。
* `--yes` / `-y` — 跳过提示（用于自动化）。

解析后的策略是进程级硬性覆盖——单个请求不能通过 `enable_tools=true` 在请求体中绕过它。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FeIJIvZl7HvOCjtVPm3en%2Funsloth_run_model.png?alt=media&amp;token=84c45c38-78a9-4b55-b9b7-08bad9dc6238" alt=""><figcaption></figcaption></figure></div>

### 🌐 端点

Unsloth 会在其启动的端口上暴露 API，通常是 `http://localhost:8000` 或 `http://localhost:8888`.

通过每个请求中的 `Authorization: Bearer sk-unsloth-…` 标头进行身份验证。端点可用性取决于你的 Unsloth 版本、后端和模型。

**聊天与文本**

| 端点                          | 用途                                                            |
| --------------------------- | ------------------------------------------------------------- |
| `POST /v1/chat/completions` | 与 OpenAI 兼容的聊天补全，包括流式传输和工具调用。                                 |
| `POST /v1/responses`        | 适用于 Codex 和其他兼容客户端的 OpenAI 兼容 Responses API。                  |
| `POST /v1/messages`         | 适用于 Claude Code、OpenClaw 和其他兼容客户端的 Anthropic 兼容 Messages API。 |
| `POST /v1/completions`      | 不带聊天格式的文本补全。需要 GGUF 或 MLX 模型。                                 |

对于 Responses 请求，请在 `input`中发送对话历史。通过服务器管理的 `previous_response_id` 或 `conversation` 不受支持。

**模型、嵌入和 token 计数**

| 端点                               | 用途                                           |
| -------------------------------- | -------------------------------------------- |
| `GET /v1/models`                 | 列出已加载和本地可用的模型。查看 `loaded` 以识别当前在内存中的模型。      |
| `GET /v1/models/{model_id}`      | 获取模型的元数据。                                    |
| `GET /v1/props`                  | 读取与 llama-server 兼容的服务器属性。                   |
| `POST /v1/embeddings`            | 使用已加载的 embedding GGUF 或 Unsloth 配置的嵌入模型生成嵌入。 |
| `POST /v1/chat/count_tokens`     | 统计 OpenAI 格式消息的提示词 token 数。                  |
| `POST /v1/messages/count_tokens` | 统计 Anthropic 格式消息的输入 token 数。                |

**图像**

| 端点                            | 用途                   |
| ----------------------------- | -------------------- |
| `POST /v1/images/generations` | 使用受支持的扩散模型根据提示词生成图像。 |

**音频**

| 端点                              | 用途                                 |
| ------------------------------- | ---------------------------------- |
| `POST /v1/audio/speech`         | 与 OpenAI 兼容的文本转语音。                 |
| `POST /v1/audio/generate`       | 根据聊天格式消息生成语音；返回 base64 编码的 WAV 音频。 |
| `POST /v1/audio/transcriptions` | 转录上传的音频文件。                         |
| `POST /v1/audio/translations`   | 将上传音频文件中的语音翻译成英语。                  |
| `POST /v1/audio/inputs`         | 上传音频以供复用。将音频作为原始请求体发送。             |
| `POST /v1/audio/run`            | 根据模型运行音频工作流，例如克隆、编辑、转换、音乐生成或分离。    |

已存储的音频输入支持 `GET /v1/audio/inputs/{input_id}/file` 和 `DELETE /v1/audio/inputs/{input_id}`.

通过以下方式管理已保存的语音 `GET` 或 `POST /v1/audio/voices`, `PATCH` 或 `DELETE /v1/audio/voices/{voice_id}`，以及 `GET /v1/audio/voices/{voice_id}/file`.

**视频**

| 端点                                  | 用途          |
| ----------------------------------- | ----------- |
| `POST /v1/videos`                   | 创建一个视频生成任务。 |
| `GET /v1/videos`                    | 列出视频任务。     |
| `GET /v1/videos/{video_id}`         | 获取任务状态和元数据。 |
| `GET /v1/videos/{video_id}/content` | 下载已完成的视频。   |
| `DELETE /v1/videos/{video_id}`      | 删除一个视频任务。   |

图像、音频和视频生成需要支持所请求任务的模型。

**结构化决策**

| 端点                   | 用途                       |
| -------------------- | ------------------------ |
| `POST /v1/systemone` | 使用 Decision API 回答结构化问题。 |

在以下位置启用 Decision API **设置 → API** 并且首先选择一个决策模型。请求使用 `状态` 和命名为 `问题`，问题类型为 `空值`, `选择`，或 `得分`.

**浏览你的本地 API**

打开 `http://localhost:8888/docs` ，查看 Unsloth 生成的交互式 API 参考，或者 `/openapi.json` 查看其机器可读的模式。将 `8888` 替换为你的 Unsloth 端口。

此参考反映你已安装的版本，并包含内部 Unsloth 路由。有些兼容路由被隐藏，手动解析的请求体可能没有完整的 schema。

参见 [Curl 和 HTTP](https://unsloth.ai/docs/integrations/connect-curl-and-http-to-unsloth) 获取请求示例。

### 🖇️ 连接你的客户端

Unsloth 让你可以通过大多数框架在本地运行 LLM，包括 [Claude Code](/docs/zh/ji-chu-zhi-shi/claude-code.md), [Codex](/docs/zh/ji-chu-zhi-shi/codex.md), [OpenClaw](/docs/zh/ji-cheng/openclaw.md), [OpenCode](/docs/zh/ji-cheng/opencode.md) 等。点击下面的具体工具查看指南：

{% columns %}
{% column width="50%" %}
{% content-ref url="/pages/1a707991086189a8e5cd8374f3ce1b81915bc159" %}
[Claude Code](/docs/zh/ji-chu-zhi-shi/claude-code.md)
{% endcontent-ref %}

{% content-ref url="/pages/b71ddea7924324c058a771e5e831c3cb6fc75b18" %}
[OpenAI Codex](/docs/zh/ji-chu-zhi-shi/codex.md)
{% endcontent-ref %}

{% content-ref url="/pages/4636d45e7e20328c61211d43c235257fdd7ebc1d" %}
[Curl & HTTP](/docs/zh/ji-cheng/jiang-curl-he-http-lian-jie-dao-unsloth.md)
{% endcontent-ref %}
{% endcolumn %}

{% column width="50%" %}
{% content-ref url="/pages/f1eb04d9bdae8f6dbb3d9ed5d64e060dac5a68ff" %}
[OpenClaw](/docs/zh/ji-cheng/openclaw.md)
{% endcontent-ref %}

{% content-ref url="/pages/124bfded8d8412a9fbc1614fa7467985c0af22da" %}
[OpenCode](/docs/zh/ji-cheng/opencode.md)
{% endcontent-ref %}

{% content-ref url="/pages/010e01be868ae39c13b48ffdf9774e645c6a347f" %}
[Python SDK](/docs/zh/ji-cheng/jiang-python-sdk-lian-jie-dao-unsloth.md)
{% endcontent-ref %}
{% endcolumn %}
{% endcolumns %}

要从另一台机器访问此端点，请使用以下方式启动 `unsloth studio --secure`。Unsloth 会保持绑定到 localhost，并通过一个免费的 Cloudflare HTTPS URL 对外发布自身；请用该 URL 替换 `http://127.0.0.1:8888` 作为客户端的 base URL。请注意，服务器发送事件无法通过 Cloudflare 快速隧道保留，因此在通过它调用时请设置 `stream: false` 。

### 🧰 工具调用

两个端点都支持以原生格式进行函数/工具调用，另外还支持 Unsloth 专用的简写，用于 Unsloth 内置工具。

**OpenAI 风格的工具：** 发送 `工具` 和 `tool_choice` 到 `/v1/chat/completions` ，就像你在 OpenAI 中会做的那样。Claude Code（通过 `/v1/messages`），opencode、Cursor、Continue 和 Cline 都可开箱即用。

**Anthropic 风格的工具：** 发送 `工具` （带有 `input_schema`）和 `tool_choice` 到 `/v1/messages` ，就像你在 Claude 中会做的那样。

Unsloth 服务器端工具：Unsloth 可以在服务器端执行 Python、网页搜索和 bash *服务器端* ，并将结果以 `tool_result` 事件流式返回。通过在任一端点添加这些额外字段来启用它们：

```json
{
  "messages": [{"role": "user", "content": "123 * 456 是多少？请使用 Python。"}],
  "stream": true,
  "enable_tools": true,
  "enabled_tools": ["python", "web_search","terminal"],
  "session_id": "my-session"
}
```

模型会在下一轮看到每个工具的输出。有关更深入的覆盖（模式、流式事件、链式调用），请参见。

{% hint style="info" %}
如果你使用 Anthropic `/v1/messages` 端点， `tool_choice` 映射很直接：Anthropic `自动` → OpenAI `自动`，Anthropic `任意` → OpenAI `必需`，Anthropic `{type: "tool", name: "x"}` → OpenAI `{type: "function", function: {name: "x"}}`，Anthropic `无` → OpenAI `无`.
{% endhint %}

### 📈 API 监控

通过此端点的每次调用都会实时列在 Unsloth 中，位置有两个：

一旦 API 密钥流量到达，API 监控侧边栏就会自动在角落打开。它会汇总活动模型、实时请求、错误和平均延迟。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FqbcbkrU9tnkg5VCnDzCz%2Fimage.png?alt=media&amp;token=733b2b37-4e57-48c6-b826-9f356d648344" alt=""><figcaption></figcaption></figure></div>

按下“展开为完整监控”或前往 设置>API 监控，进入完整 **API** 页面，在监控中会显示模型加载、提示、响应、令牌计数、首个令牌耗时、吞吐量和错误消息。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FfjIh57Mb278c072g27nk%2Fimage.png?alt=media&amp;token=3a236c7c-1f00-430b-92f3-42799346aa3c" alt="" width="563"><figcaption></figcaption></figure></div>

### ❔ 故障排除

**`401 未经授权`** ：要么 `Authorization` 标头缺失，要么密钥错误。密钥必须以 `Authorization: Bearer sk-unsloth-…`。如果你丢失了密钥，请从 **设置 → API。** Unsloth 不会在创建后显示旧密钥。

**`与模型服务器的连接丢失`** ：Unsloth 无法连接到底层的 llama.cpp 服务器。通常是模型已完成加载但崩溃了，或者模型标签页在 Unsloth 内部被关闭了。请从 **新聊天** 重新加载模型并重试。

**Claude Code 显示的是默认 Anthropic 模型，而不是我的本地模型** ：请检查这三个环境变量是否都已在 **同一个** shell 中导出，在该 shell 里你运行 `claude`:

```bash
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_AUTH_TOKEN
echo $ANTHROPIC_MODEL
```

然后运行 `/model` 在 Claude Code 内确认。在 Windows PowerShell 中使用 `$env:ANTHROPIC_BASE_URL` 等。

**`stream: true` 返回单个 JSON 数据块，而不是 SSE** ：请确保你打到了正确的路径（`/v1/messages` 或 `/v1/chat/completions`），并且你的 HTTP 客户端实际上是按流消耗响应，而不是缓冲它。

**我找不到要添加到 opencode（或 OpenClaw / 任何其他客户端）的模型名称** ：直接向 Unsloth 询问。 `GET /v1/models` 返回你需要填入客户端“模型 ID”字段的准确模型 ID：

```bash
curl http://localhost:8888/v1/models \\
  -H "Authorization: Bearer sk-unsloth-xxxxxxxxxxxx"
```

你将收到如下形式的 JSON 负载 `{"data": [{"id": "gemma-4-26B-A4B-it-GGUF", ...}]}`。复制 `id` 值，就是 opencode 的 **模型 ID** 字段（左列）和 OpenClaw 的 `models[].id` 所期望的内容。右侧的显示名称可以是你希望用户看到的任何内容。

**工具调用未执行** ：模型需要支持客户端侧工具的工具调用（`工具` / `tool_choice`）。对于 Unsloth 的内置工具，记得设置 `enable_tools: true` **和** 并在 `enabled_tools` 中列出你想要的工具（例如 `["python", "web_search"]`).

* **我的客户端报告连接错误。** 打开 API 监控。如果该调用没有对应行，则说明它从未到达 Unsloth，请将你客户端的 base URL 与该页面顶部显示的 **基础 URL** 进行比较。
* **回复被截断了。** 检查 **API 监控中的该请求所使用的** 。接近 100%，或停止原因是 `length`，都意味着上下文窗口已满，而不是模型失败。


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/zh/ji-chu-zhi-shi/api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
