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

# 如何将 OpenRouter 连接到 Unsloth：API 密钥与模型设置

本指南将解释如何连接 **OpenRouter 到** [**Unsloth**](https://github.com/unslothai/unsloth) ，这样你就可以通过一个开源的本地 UI 聊天界面访问来自以下提供商的托管 AI 模型： **OpenAI、Anthropic、** 和 **Google** 。你将学习如何创建 OpenRouter API 密钥，在 Unsloth 中将 OpenRouter 添加为提供商，加载或手动输入模型 ID，并为聊天启用外部模型。

一旦连接了一个 API 密钥，Unsloth 中的 OpenRouter 模型就可以直接在聊天页面提供高级功能，例如思考、网页搜索、工具调用、代码执行以及可自定义的生成设置。

### 设置

{% stepper %}
{% step %}

#### 创建 OpenRouter API 密钥

登录你的 OpenRouter 账户。从 [OpenRouter 仪表板](https://openrouter.ai/settings/keys):

<figure><img src="/files/9ab2dc6fdd546c098d0ec3bb4508765837c24540" alt="" width="563"><figcaption></figcaption></figure>

创建 API 密钥。复制该密钥。下一步你会将它粘贴到 Unsloth 中。

创建密钥时，你可以选择设置信用额度上限或过期日期。
{% endstep %}

{% step %}

#### 将 OpenRouter 连接到 Unsloth

打开 **设置 → 连接**，然后点击 **添加连接**.

选择 **OpenRouter**，然后输入你的连接详情。

输入你的 OpenRouter 详情：

* **API 密钥：** 粘贴你的 OpenRouter API 密钥

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

* **模型 ID：** 点击 **加载模型**，或手动输入模型 ID

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

最后，点击 **添加连接**.&#x20;
{% endstep %}

{% step %}

#### 准备聊天

保存连接后，在模型下拉菜单中的 **已连接** 下选择一个 OpenRouter 模型。

<figure><img src="/files/cefcf9636620bacdef3e8a327f36800b20375374" alt="" width="337"><figcaption></figcaption></figure>

OpenRouter 模型会根据上游模型提供不同的控制项，包括网页搜索、思考、工具调用和生成设置。
{% endstep %}
{% endstepper %}

### 模型选择

OpenRouter 可让你访问来自不同提供商的许多模型。如果 **加载模型** 未返回你想选择的模型，请输入你希望启用的模型 ID。

<figure><img src="/files/1c2ff9eada734d533e27f9ff33bf48c46d1ff8fd" alt="" width="563"><figcaption></figcaption></figure>

示例模型 ID：

```
openai/gpt-5.5 
anthropic/claude-sonnet-4.6 
google/gemini-3-pro
```

### 故障排除

如果 OpenRouter 连接失败，请检查 API 密钥是否有效，以及是否属于正确的 OpenRouter 账户。

如果点击 **加载模型**后某个模型没有出现，它可能不适用于你的账户或地区。你可以手动输入模型 ID，或者选择另一个模型。


---

# 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/openrouter.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.
