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

# 将 Anthropic 连接到 Unsloth：在本地聊天中运行 Claude 模型

将 Anthropic API 连接到 [Unsloth](https://github.com/unslothai/unsloth) 即可直接在开源 UI 聊天界面中，与 Claude 模型（包括 Claude Opus 4.7）以及你的本地模型聊天。本指南将向你展示如何创建 Anthropic API 密钥、在 Unsloth 中将 Anthropic 添加为提供方、加载 Claude LLM 并开始聊天。

Unsloth 中受支持的 Claude 模型还可以访问高级功能，例如思考、 [网页搜索](#web-search-and-thinking)、Anthropic [代码执行](#code-execution)以及 [提示缓存](#prompt-caching) ，以提高成本效率。

### 设置

{% stepper %}
{% step %}

#### 创建 Anthropic API 密钥

从 [Anthropic 控制台](https://console.anthropic.com/settings/keys)创建一个 API 密钥。复制该密钥。下一步你会将其粘贴到 Unsloth 中。
{% endstep %}

{% step %}

#### 将 Anthropic 连接到 Unsloth

<figure><img src="/files/2fd7ee6b0593c650cce816a0a3e91dd69a720ac9" alt="" width="563"><figcaption></figcaption></figure>

接下来，将 Anthropic 连接到 Unsloth。

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

{% step %}

#### 准备聊天

保存连接后，在模型下拉菜单中的 **已连接** 下选择一个 Claude 模型。受支持的 Claude 模型可以显示额外控件，包括图像生成、思考、网页搜索和代码执行。

<figure><img src="/files/fff16ad21df2c12ce903bddcce84020e45490223" alt="" width="337"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### 代码执行

启用后，受支持的 Claude 模型可以在 Anthropic 的提供方沙盒中运行代码，以解决问题、分析数据并处理文件。Claude 使用 Anthropic 的代码执行工具。代码执行会与其他工具调用一起，作为工具活动出现在响应时间线中。

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

### 提示缓存

{% columns %}
{% column width="66.66666666666666%" %}
当请求重复使用相同的长前缀时，提示缓存可降低延迟和成本。它适用于兼容的提供方和服务器，包括 Anthropic 模型。使用侧边栏中的 **提示缓存** 设置来控制受支持连接的缓存行为。
{% endcolumn %}

{% column width="33.33333333333334%" %}

<figure><img src="/files/d6f9c983151da4e69220e65a1086fe46b531e400" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

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

### 网页搜索与思考

受支持的 Claude 模型可以使用提供方侧的网页搜索。 **思考** 控件会在所选模型支持思考时出现。根据模型不同，这可能会显示不同的思考级别或可用性。

<figure><img src="/files/6bcbf73e630a7bdafe6fe54e520fe6d02cc53e3e" alt="" width="563"><figcaption></figcaption></figure>

该 **思考** 控件会根据所选模型进行调整：有些模型使用开关，而推理强度模型则使用特定于模型的思考级别。&#x20;

### 故障排除

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

如果点击 **加载模型**后没有出现某个模型，它可能不适用于你的账户。你可以手动输入模型 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:

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