> 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="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FPTauJusYHSZXfrRVPRRF%2Funsloth_openai_api.gif?alt=media&amp;token=54ae6d0f-57d8-41c5-b40d-168fad73482a" 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="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fcw5I5BX3fx8Kf5LDUwl0%2Funsloth_cloud_provider_setup.gif?alt=media&amp;token=8babf957-7486-4a8d-ab5e-6d3b36a2b3ba" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### 准备聊天

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

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FgKCJ3zsZzZuDqBAigsfG%2FScreenshot%202026-05-26%20at%201.31.03%E2%80%AFAM.png?alt=media&amp;token=c8df4285-ba69-4091-8978-e4197f6a12d2" 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="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F4PC8ybPZgdcdhOWkduFR%2Fimage.png?alt=media&amp;token=00956d7e-4d26-462d-b5a4-17cfb9717aaf" alt="" width="375"><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

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

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

### 代码执行

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

<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%2F4W9Zq684jCgJy9kGvrkk%2FScreenshot%202026-05-26%20at%206.10.12%E2%80%AFAM.png?alt=media&amp;token=c7b6a106-1a22-4120-a22d-f9ad8a9471c7" alt="" width="563"><figcaption></figcaption></figure></div>

### 提示缓存

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

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fq4csmTX5rS9isMkNkhTX%2FPrompt%20Caching%20Diagram%20(1).png?alt=media&amp;token=ade433bf-5eaf-4146-a266-525a85a6c98d" 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="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FC0Ed4kzN9h6c0ogEn6NT%2Fwebsearch%20api.png?alt=media&amp;token=d3335222-1d9e-4021-9bf9-734c6acf1fc0" alt="" width="563"><figcaption></figcaption></figure></div>

### 图像生成

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

<div><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F5ZLU2BY19MN4yiYLx2Br%2FScreenshot%202026-05-26%20at%206.04.34%E2%80%AFAM.png?alt=media&amp;token=44327a8f-c14d-4541-9a02-f19f375b4326" alt=""><figcaption></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FDQ1bJ5KF8CiyItrfOrIt%2FScreenshot%202026-05-26%20at%206.06.07%E2%80%AFAM.png?alt=media&amp;token=ff6b00bc-0a2f-4375-a454-49429cf839f2" 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 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-cheng/connections.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.
