> 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/connections.md).

# 将 API 提供方和模型服务器连接到 Unsloth

了解如何通过单一的本地 UI 界面运行来自 OpenAI、Anthropic、Ollama、llama.cpp、vLLM 以及其他提供商的模型，并配合 [Unsloth](/docs/zh/xin-zeng/studio.md)，这是一个用于运行和训练 LLM 的开源仓库。

{% columns %}
{% column %}
连接后，你可以在同一个 Unsloth 聊天界面中运行模型，使用代码执行、工具调用、图像生成及其他功能，适用于本地和云端模型。

Unsloth 独特支持 [提示缓存](#prompt-caching) （可在不降低准确性的情况下为你节省大量 token），同时保留对提供商原生能力的访问，例如 OpenAI 内置的 [网页搜索](#web-search-and-thinking) 和 [代码执行](#code-execution).
{% endcolumn %}

{% column %}
{% embed url="<https://github.com/user-attachments/assets/70456395-e016-4273-8256-35adb206267e>" %}
{% endcolumn %}
{% endcolumns %}

### 连接

连接分为两类：为你托管运行模型的云端 API 提供商，以及由你自己运行或控制的模型服务器。

**云提供商 -** 使用账户 API 密钥的托管 API：

| 连接         | 功能                   | 设置指南                                                             |
| ---------- | -------------------- | ---------------------------------------------------------------- |
| OpenAI     | 图像、搜索、代码、思考          | [OpenAI →](/docs/zh/ji-cheng/connections/openai.md)              |
| Anthropic  | 图像、搜索、代码、思考          | [Anthropic →](/docs/zh/ji-cheng/connections/anthropic-claude.md) |
| OpenRouter | 通过一个 API 密钥访问多个托管模型。 | [OpenRouter →](/docs/zh/ji-cheng/connections/openrouter.md)      |

**模型服务器 -** 在本地、网络中或远程机器上运行的推理服务器：

| 服务器       | 说明            | 指南                                                                                                                      |
| --------- | ------------- | ----------------------------------------------------------------------------------------------------------------------- |
| Llama.cpp | 高效的 GGUF 模型服务 | [Llama.cpp →](/docs/zh/ji-cheng/connections/jiang-llama.cpp-lian-jie-dao-unsloth-shi-yong-llamaserver-yun-xing-gguf.md) |
| vLLM      | 高吞吐量服务        | [vLLM →](/docs/zh/ji-cheng/connections/vllm.md)                                                                         |
| Ollama    | 简单的本地模型服务器    | [Ollama →](/docs/zh/ji-cheng/connections/ollama.md)                                                                     |

### 快速开始

要运行外部提供商的模型，请添加 API 密钥并选择 Unsloth 应显示哪些模型。在此示例中，我们将使用 [OpenAI](https://platform.openai.com/api-keys)。同样的设置也适用于 Anthropic 以及其他提供商。

{% stepper %}
{% step %}

#### 创建 API

从提供商控制台创建一个新的 API 密钥并复制它。

<figure><img src="/files/d6de545bddd5a99f3ef7d177d5c153ccb2c6ef14" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### 设置 Unsloth Studio

现在我们需要安装并设置 [Unsloth](/docs/zh/xin-zeng/studio.md)，这将使你能够在 UI 界面中运行云端模型。 [请看这里](/docs/zh/xin-zeng/studio/install.md) 以获取更详细的说明。

{% tabs %}
{% tab title="MacOS" %}

#### 第 1 步：设置 Unsloth

启动 `终端` ，然后输入以下命令安装 Unsloth。

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

环境和所需软件包现在将开始安装。输入 `Y` 并在提示继续时按 Enter。设置完成后，服务器将在本地端口 `8888`.

<figure><img src="/files/5f519c6be67e8e04d146b8890e77a97ea1d57b24" alt="" width="375"><figcaption></figcaption></figure>

{% hint style="info" %}
如果你在安装过程中跳过了启动应用，现在可以使用以下命令稍后启动它 `unsloth studio -p 8888`。若要允许来自网络中其他设备的连接，请使用 `unsloth studio -H 0.0.0.0 -p 8888` 替代。
{% endhint %}

#### 第 2 步：启动 Unsloth

打开你常用的浏览器并输入 `http://127.0.0.1:8888`  到 URL 栏中。如果这是你第一次安装 Unsloth，你将被转到密码页面，需要创建一个新密码。然后你应该会看到如下所示的聊天页面。

<figure><img src="/files/752cee75840c3ad7dcf1d7c341a194e63895ac0e" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Windows" %}

#### 第 1 步：设置 Unsloth

打开开始菜单，搜索 `PowerShell`，并启动它。复制并输入安装命令：

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

它将自动开始安装。安装完成后，PowerShell 会询问你是否要启动 Unsloth Studi&#x6F;**.**

<figure><img src="/files/5f519c6be67e8e04d146b8890e77a97ea1d57b24" alt="" width="375"><figcaption></figcaption></figure>

你也可以使用以下命令启动它：

```bash
unsloth studio -H 0.0.0.0 -p 8888
```

{% hint style="info" %}
如果你希望你的实例可被 PC/电脑外部的客户端访问。\
添加 `-H 0.0.0.0` 到 `unsloth studio` 命令中。
{% endhint %}

#### 第 2 步：启动 Unsloth

打开 `http://127.0.0.1:8888` 在浏览器中。首次启动时，创建一个新密码以继续进入聊天页面。 **Unsloth Studio** 现已安装完毕，可供使用。

<figure><img src="/files/752cee75840c3ad7dcf1d7c341a194e63895ac0e" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Linux、WSL" %}

#### 第 1 步：设置 Unsloth

{% tabs %}
{% tab title="Linux" %}
打开你的终端应用。你可以通过按 `Ctrl + Alt + T`，或者搜索 `终端` 在系统应用菜单中找到它。
{% endtab %}

{% tab title="WSL" %}
点击 Windows 开始菜单，输入你已安装的发行版名称（例如 `Ubuntu`），然后打开它。

{% hint style="warning" %}
在 **WSL**，请确保你的 **NVIDIA 驱动程序** 已安装在 **Windows** （而不是在 WSL 内部），并且 **CUDA 工具包** 已安装在你的 WSL 发行版中。详情请参阅下方的系统要求。
{% endhint %}
{% endtab %}
{% endtabs %}

要安装，请复制并运行安装命令：

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

然后：

1. 点击终端窗口内部
2. 使用 `Ctrl + Shift + V`
3. 按 `Enter`

Unsloth 将开始设置环境并安装所需的软件包，如下所示。输入 **Y** 并按 `Enter` 当被询问是否允许 Studio 现在启动时。这将使 Unsloth 在你的本地 **8888** 端口上启动。

<figure><img src="/files/6f5baa1b6cb53a7720aa0f8a23166f0ba32cb456" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
如果你在安装过程中选择不启动 Unsloth，随时可以使用 `unsloth studio -p 8888` 。如果你希望你的 Unsloth 实例可被 PC/电脑外部的客户端访问，请添加 `-H 0.0.0.0` 到 `unsloth studio` 命令中。
{% endhint %}

#### 第 2 步：启动 Unsloth

打开你常用的浏览器并输入 `http://127.0.0.1:8888`  到 URL 栏中。如果这是你第一次安装 Unsloth，你将被转到密码页面，需要创建一个新密码。之后，Unsloth 应该会打开到如下所示的聊天页面。

<figure><img src="/files/2426649b2fc23e17ba8d2ed31e9afcf2ccc21ee0" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

#### 配置连接

接下来，将你的提供商连接到 Unsloth。

1. 打开 **设置** → **连接**，然后点击 **添加连接。**
2. 选择你要添加的提供商，然后粘贴你之前复制的 API 密钥。
3. 点击 **重新加载模型** 以刷新列表，显示你账户可用的模型。
4. 选择你要启用的模型，然后点击保存。&#x20;

<figure><img src="/files/a0ff542ae56e9f58b29f9ddcc71b0efd0c74cdd5" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### 准备聊天

你启用的模型现在将显示在 **已连接** 的 **选择模型** 下拉菜单中。

<figure><img src="/files/1952f178410c905ec63ebcb843c7b1dae8de802c" alt="" width="563"><figcaption></figcaption></figure>

Unsloth 会动态显示不同模型兼容的推理级别和生成控制。
{% endstep %}
{% endstepper %}

### 连接模型服务器

请使用此流程连接 [**llama.cpp**](/docs/zh/ji-cheng/connections/jiang-llama.cpp-lian-jie-dao-unsloth-shi-yong-llamaserver-yun-xing-gguf.md), [**vLLM**](/docs/zh/ji-cheng/connections/vllm.md)，以及 [**Ollama**](/docs/zh/ji-cheng/connections/ollama.md)。启动或找到你要连接的服务器。 &#x20;

{% tabs %}
{% tab title="llama.cpp " %}
启动 `llama-server` 并使用你要提供服务的模型：

```bash
llama-server \
  --model /path/to/model.gguf \
  --host 0.0.0.0 \
  --port 8080
```

这会在以下地址暴露一个 API 端点： `http://localhost:8080/v1`

若要要求 API 密钥，请添加：

```bash
--api-key 1234-myapi-key
```

{% endtab %}

{% tab title="vLLM" %}
启动 `vLLM` 并使用你要提供服务的模型启动服务器：

```bash
  vllm serve unsloth/gemma-4-26B-A4B-it \
  --dtype auto \
```

若要要求 API 密钥，请添加：

```bash
  --api-key token-abc123
```

这会在以下地址暴露一个 API 端点： `http://localhost:8000/v1`
{% endtab %}

{% tab title="Ollama" %}
启动 `Ollama`，然后拉取你要使用的模型：

```bash
ollama serve
ollama pull qwen3:14b
```

这会在以下地址暴露一个 API 端点： `http://localhost:11434/v1`
{% endtab %}
{% endtabs %}

{% columns %}
{% column %}
现在我们可以连接模型服务器。打开 **设置 → 连接**，然后点击 **添加提供商**.

选择 llama.cpp、vLLM 或 Ollama，然后粘贴服务器的 **基础 URL**.

* llama.cpp 示例： `http://localhost:8080/v1`
* Ollama 示例： `http://localhost:11434/v1`
  {% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="/files/9fb88a939de349ff6605cf4a3206e0a86c3a2d2c" alt="" width="375"><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

点击 **加载模型** 以获取可用的模型 ID；如果你的服务器没有公开 `/models`.

然后，在你点击 **添加提供商** 你启用的模型现在将显示在 **后，** 的 **选择模型** 下拉菜单中。

### 外部

启用后，受支持的 OpenAI 和 Anthropic 模型可以在提供商沙盒中运行代码，以解决问题、分析数据并处理文件。\
\
Anthropic 模型使用 Claude 的提供商侧代码执行工具。OpenAI 使用可重复使用的容器，你可以从中创建、删除和选择 **外部** 设置中进行管理。在新线程中选择同一个容器，可继续使用其中的文件和状态。

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

### 提示缓存

当请求复用相同的长前缀时，提示缓存可以降低延迟和成本。它适用于兼容的提供商和服务器，包括 OpenAI、Anthropic 和 llama.cpp。使用 **提示缓存** 侧边栏中的设置来控制受支持连接的缓存行为。

<figure><img src="/files/bc3e271f222fc77ddeb9a8e6a3a0f766111f369e" alt="" width="375"><figcaption></figcaption></figure>

对于 llama.cpp，提示缓存默认启用，并可在启动时通过以下方式禁用 `llama-server` 使用：

```bash
--no-cache-prompt
```

### 网页搜索与思考

提供商侧网页搜索适用于 OpenAI、Anthropic、OpenRouter、Mistral、Gemini 和 Kimi 的受支持模型。Think 控件会适配所选模型：某些模型使用开关，而推理强度模型使用特定于模型的思考级别。

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

### 图像生成

就像 GPT 和 Gemini 一样，Unsloth 也支持图像生成。你可以点击“编辑图像”按钮并输入新的提示词来直接编辑图像，以优化或重新生成它。系统会在请求时自动生成图像，但你可以关闭此行为。还提供下载按钮，让你以原始全分辨率保存图像。

<div><figure><img src="/files/992af313182ce1bfb26abe80be33754c4a620bca" alt=""><figcaption></figcaption></figure> <figure><img src="/files/a322cfb7cd9de5a40a53f03a07bb05985985d524" alt=""><figcaption></figcaption></figure></div>

### 故障排查

如果提供商连接失败，请检查 API 密钥是否属于所选提供商，并且是否有权访问你选择的模型。

如果某个模型在点击后没有出现 **重新加载模型**，它可能不适用于你的账户。你仍然可以使用 Unsloth 的默认模型列表，或选择其他模型。


---

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

```
GET https://unsloth.ai/docs/zh/ji-cheng/connections.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.
