Optionalfields: anyOptionalanthropicAnthropic API key
OptionalapiAnthropic API key
OptionalapiProtectedbatchOptionalbetasOptional array of beta features to enable for the Anthropic API. Beta features are experimental capabilities that may change or be removed. See https://docs.claude.com/en/api/beta-headers for available beta features.
Overridable Anthropic ClientOptions
OptionalcontextConfiguration for context management. See https://docs.claude.com/en/docs/build-with-claude/context-editing
Optional method that returns an initialized underlying Anthropic client. Useful for accessing Anthropic models hosted on other cloud services such as Google Vertex.
OptionalinvocationHolds any additional parameters that are valid to pass to anthropic.messages that are not explicitly specified on this class.
A maximum number of tokens to generate before stopping.
Model name to use
OptionalstopA list of strings upon which to stop generating.
You probably want ["\n\nHuman:"], as that's the cue for
the next turn in the dialog agent.
Whether to stream the results or not
ProtectedstreamingWhether or not to include token usage data in streamed chunks.
OptionaltemperatureAmount of randomness injected into the response. Ranges from 0 to 1. Use temperature closer to 0 for analytical / multiple choice, and temperature closer to 1 for creative and generative tasks.
Options for extended thinking.
OptionaltopOnly sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses.
OptionaltopDoes nucleus sampling, in which we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. Note that you should either alter temperature or top_p, but not both.
Return profiling information for the model.
Provides information about the model's capabilities and constraints, including token limits, multimodal support, and advanced features like tool calling and structured output.
An object describing the model's capabilities and constraints
Optionalkwargs: Partial<ChatAnthropicCallOptions>ProtectedcreateCreates a streaming request with retry.
The parameters for creating a completion.
Optionaloptions: RequestOptionsA streaming request.
Formats LangChain StructuredTools to AnthropicTools.
The tools to format
The formatted tools, or undefined if none are passed.
Get the identifying parameters for the model
Get the parameters used to invoke the model
Optionaloptions: unknownOptionalconfig: anyOptionalconfig: anyStaticlc_
Anthropic chat model integration.
Setup: Install
@langchain/anthropicand set an environment variable namedANTHROPIC_API_KEY.Constructor args
Runtime args
Runtime args can be passed as the second argument to any of the base runnable methods
.invoke..stream,.batch, etc. They can also be passed via.bind, or the second arg in.bindTools, like shown in the examples below:Examples
Instantiate
Invoking
Streaming Chunks
Aggregate Streamed Chunks
Bind tools
Tool Search
Tool search enables Claude to dynamically discover and load tools on-demand instead of loading all tool definitions upfront. This is useful when you have many tools but want to avoid the overhead of sending all definitions with every request.
You can also use the
tool()helper with theextrasfield:Note: The required
advanced-tool-use-2025-11-20beta header is automatically appended to the request when using tool search tools.Best practices:
defer_loading: trueare only loaded when Claude discovers them via searchSee the Claude docs for more information.
Structured Output
ChatAnthropic supports structured output through two main approaches:
withStructuredOutput(): Uses Anthropic's tool calling under the hood to constrain outputs to a specific schema.Using withStructuredOutput (Function Calling)
This method leverages Anthropic's tool calling capabilities to ensure the model returns data matching your schema:
Using JSON Schema Mode
For more direct control, you can use Anthropic's native JSON schema support by passing
method: "jsonSchema":Multimodal
Usage Metadata
Stream Usage Metadata
Response Metadata