> 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/desktop.md)，这是一个用于运行和训练 LLM 的开源仓库。你也可以将你的 ChatGPT/Codex 订阅直接连接到 Unsloth。

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

{% 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：

| 连接              | 功能                   | 设置指南                                                             |
| --------------- | -------------------- | ---------------------------------------------------------------- |
| ChatGPT / Codex | 图像、搜索、代码、思考          | [OpenAI →](/docs/zh/ji-cheng/connections/openai.md)              |
| 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-mo-xing.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 %}

#### 设置 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
```

[请看这里](/docs/zh/desktop.md#get-started) 获取更详细的说明
{% endstep %}

{% step %}

#### 创建 API

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

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

{% step %}

#### 设置 Unsloth

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

{% 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-mo-xing.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, and the optional `goal` query parameter:

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