wrapAnthropic<T extends AnthropicType>(
anthropic: T,
options: Partial<RunTreeConfig>
): PatchedAnthropicClient<T| Name | Type | Description |
|---|---|---|
anthropic* | T | |
options | Partial<RunTreeConfig> |
Wraps an Anthropic client's completion methods, enabling automatic LangSmith tracing. Method signatures are unchanged, with the exception that you can pass an additional and optional "langsmithExtra" field within the second parameter.
An Anthropic client instance.
LangSmith options.
import Anthropic from "@anthropic-ai/sdk";
import { wrapAnthropic } from "langsmith/wrappers/anthropic";
const anthropic = wrapAnthropic(new Anthropic());
// Non-streaming
const message = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
});
// Streaming
const messageStream = anthropic.messages.stream({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
});
const finalMessage = await messageStream.finalMessage();