Laminar automatically instruments the official Anthropic package with a single line of code, allowing you to trace and monitor all your Anthropic API calls without modifying your existing code. This provides complete visibility into your AI application’s performance, costs, and behavior.
Just add a single line at the start of your application or file to instrument Anthropic with Laminar.
Copy
import { Laminar } from '@lmnr-ai/lmnr';import Anthropic from '@anthropic-ai/sdk';import 'dotenv/config'; // Load environment variables// This single line instruments all Anthropic API callsLaminar.initialize({ instrumentModules: { anthropic: Anthropic }});// Initialize Anthropic client as usualconst anthropic = new Anthropic();
It is important to pass Anthropic to instrumentModules as a named export.
// Make API calls to Anthropic as you normally wouldconst response = await anthropic.messages.create({ model: "claude-3-7-sonnet", max_tokens: 1024, messages: [ { role: "user", content: "Hello, how are you?" } ],});console.log(response.content);
All Anthropic API calls are now automatically traced in Laminar.
These features allow you to build more structured traces, add context to your LLM calls, and gain deeper insights into your AI application’s performance.