> 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) 以便你可以访问来自以下提供商的托管 AI 模型： **OpenAI、Anthropic、** 和 **Google** 通过一个开源的本地 UI 聊天界面。你将学习如何创建 OpenRouter API 密钥，在 Unsloth 中将 OpenRouter 添加为提供商，加载或手动输入模型 ID，以及启用外部模型进行聊天。

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

### 设置

{% stepper %}
{% step %}

#### 创建 OpenRouter API 密钥

登录你的 OpenRouter 账户。从以下位置创建 API 密钥： [OpenRouter 控制面板](https://openrouter.ai/settings/keys):

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FumQXaeZGAQ8f3hMQSQQY%2Fimage.png?alt=media&amp;token=51ec273d-4271-4683-8cf2-0fb11bccb1ba" alt="" width="563"><figcaption></figcaption></figure>

复制该密钥。下一步你会将其粘贴到 Unsloth 中。

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

{% step %}

#### 将 OpenRouter 连接到 Unsloth

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

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

输入你的 OpenRouter 详情：

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

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FB9fDpRnYfDjhCI5yDoon%2Fimage.png?alt=media&amp;token=97ecc7e3-a3fe-4cd8-a5c6-738c9de7fbf3" alt="" width="375"><figcaption></figcaption></figure>

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

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F59F88IYS0BzteOqcavUj%2Fimage.png?alt=media&amp;token=72632261-b3cd-486c-b4dd-09b56fa3a58a" alt="" width="375"><figcaption></figcaption></figure>

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

{% step %}

#### 准备聊天

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

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FFFvSXoLCnvydwmTgS7Ru%2Fimage.png?alt=media&amp;token=79ca30bb-e049-4106-8b98-0871f79dfba5" alt="" width="337"><figcaption></figcaption></figure>

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

### 模型选择

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

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FQM4eHEcNpWQazKtyS06X%2Fimage.png?alt=media&amp;token=8774a4a0-7d00-4888-9e03-72c0e8641533" 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 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/openrouter.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.
