> 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) 用于与 Claude 模型（包括 Claude Opus 4.7）直接在一个开源 UI 聊天界面中与你的本地模型一起聊天。本指南将展示如何创建 Anthropic API 密钥、在 Unsloth 中将 Anthropic 添加为提供商、加载 Claude LLM，并开始聊天。

Unsloth 中支持的 Claude 模型还可以使用推理等高级功能， [网页搜索](#web-search-and-thinking)，Anthropic [代码执行](#code-execution)，以及 [提示缓存](#prompt-caching) 以提高成本效率。

### 设置

{% stepper %}
{% step %}

#### 创建 Anthropic API 密钥

从以下位置创建 API 密钥： [Anthropic Console](https://console.anthropic.com/settings/keys)。复制该密钥。你将在下一步将其粘贴到 Unsloth 中。
{% endstep %}

{% step %}

#### 将 Anthropic 连接到 Unsloth

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FSzJ57mYBpBCavIKyksDy%2Fclaude_studio_api.gif?alt=media&amp;token=bd7b7da5-bb25-4f9d-bfb8-b63602c1f082" alt="" width="563"><figcaption></figcaption></figure>

接下来，将 Anthropic 连接到 Unsloth。

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

{% step %}

#### 准备聊天

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

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FpOMKHdhunTepcJSvf8pA%2Fimage.png?alt=media&amp;token=ca454678-a98b-4edb-b407-beeb879b4f76" alt="" width="337"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### 代码执行

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

<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>

### 提示缓存

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

{% column width="33.33333333333334%" %}

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FKA6iU3qCFhUiq0KI16aU%2FScreenshot%202026-05-26%20at%203.28.44%E2%80%AFAM.png?alt=media&amp;token=41a43794-792d-48f4-8774-8b9d85702dfc" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

<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>

### 网页搜索与思考

受支持的 Claude 模型可以使用提供商端网页搜索。 **思考** 当所选模型支持推理时，会显示该控制项。根据模型不同，这可能会展示不同的推理级别或可用性。

<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>

“ **思考** 该控制项会根据所选模型进行适配：某些模型使用开/关切换，而推理强度型模型使用特定于模型的推理级别。&#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 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/anthropic-claude.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.
