Skip to main content

ChatAnthropic

LangChain supports Anthropic's Claude family of chat models.

Usage

import { ChatAnthropic } from "@langchain/anthropic";

const model = new ChatAnthropic({
temperature: 0.9,
anthropicApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.ANTHROPIC_API_KEY
maxTokensToSample: 1024,
});

API Reference:

ChatAnthropicMessages

LangChain also offers the beta Anthropic Messages endpoint through the new langchain-anthropic package.

You'll first need to install the @langchain/anthropic package:

npm install @langchain/anthropic

You'll also need to sign up and get an Anthropic API key. Set it as an environment variable named ANTHROPIC_API_KEY, or pass it into the constructor as shown below.

Usage

You can initialize an instance like this:

import { ChatAnthropicMessages } from "@langchain/anthropic";

const model = new ChatAnthropicMessages({
temperature: 0.9,
anthropicApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.ANTHROPIC_API_KEY,
maxTokens: 1024,
});

API Reference: