langchain.js
    Preparing search index...
    • 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.

      Type Parameters

      • T extends AnthropicType

      Parameters

      • anthropic: T

        An Anthropic client instance.

      • Optionaloptions: Partial<RunTreeConfig>

        LangSmith options.

      Returns PatchedAnthropicClient<T>

      The wrapped client.

      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();