> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic 集成

> 使用 LangChain JavaScript 与 Anthropic 集成。

所有与 Anthropic 模型相关的功能。

[Anthropic](https://www.anthropic.com/) 是一家专注于人工智能安全与研究的公司，也是 Claude 的创造者。
本页涵盖了 Anthropic 模型与 LangChain 之间的所有集成。

## 提示最佳实践

与 OpenAI 模型相比，Anthropic 模型在提示方面有几个最佳实践。

**系统消息可能只能是第一条消息**

Anthropic 模型要求任何系统消息必须是您提示中的第一条。

## `ChatAnthropic`

`ChatAnthropic` 是 LangChain 的 `ChatModel` 的子类，这意味着它与 `ChatPromptTemplate` 配合使用效果最佳。
您可以使用以下代码导入此包装器：

<Tip>
  请参阅[此部分了解安装 LangChain 包的一般说明](/oss/javascript/langchain/install)。
</Tip>

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/anthropic @langchain/core
```

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { ChatAnthropic } from "@langchain/anthropic";
const model = new ChatAnthropic({});
```

使用 ChatModels 时，建议您将提示设计为 `ChatPromptTemplate`。
以下是一个示例：

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { ChatPromptTemplate } from "@langchain/classic/prompts";

const prompt = ChatPromptTemplate.fromMessages([
  ["system", "You are a helpful chatbot"],
  ["human", "Tell me a joke about {topic}"],
]);
```

然后您可以按如下方式在链中使用它：

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const chain = prompt.pipe(model);
await chain.invoke({ topic: "bears" });
```

更多示例（包括多模态输入），请参阅[聊天模型集成页面](/oss/javascript/integrations/chat/anthropic/)。

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs)通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/providers/anthropic.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
