> ## Documentation Index
> Fetch the complete documentation index at: https://tracevell.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic observability

> Trace every Anthropic API call in TypeScript and Python: prompts, token usage, cost, and latency, all readable in Tracevell's transcript view.

## Overview

Tracevell 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.

## Getting Started

> [tab] TypeScript
>
> ### 1. Install Tracevell and Anthropic
>
> ```bash theme={null}
> npm install @lmnr-ai/lmnr@latest @anthropic-ai/sdk@latest
> ```
>
> ### 2. Set up your environment variables
>
> Store your API keys in a `.env` file:
>
> ```bash theme={null}
> # .env file
> LMNR_PROJECT_API_KEY=your-tracevell-project-api-key
> ANTHROPIC_API_KEY=your-anthropic-api-key
> ```
>
> Then load them in your application using a package like [dotenv](https://www.npmjs.com/package/dotenv).
>
> > [!NOTE]
> >
> > Using Anthropic inside Next.js? The [Vercel AI SDK page](https://tracevell.com/docs/integrations/vercel-ai-sdk.md#next-js-setup) covers the Next.js-specific setup (`serverExternalPackages`, `instrumentation.ts`, and `Laminar.patch` for direct SDK clients).
>
> ### 3. Initialize Tracevell
>
> Just add a single line at the start of your application or file to instrument Anthropic with Tracevell.
>
> ```typescript theme={null}
> import { Tracevell } from '@lmnr-ai/lmnr';
> import Anthropic from '@anthropic-ai/sdk';
> import 'dotenv/config'; // Load environment variables
>
> // This single line instruments all Anthropic API calls
> Laminar.initialize({
>   instrumentModules: { anthropic: Anthropic }
> });
>
> // Initialize Anthropic client
> const anthropic = new Anthropic.Anthropic();
> ```
>
> > [!NOTE]
> >
> > `import Anthropic from '@anthropic-ai/sdk'` imports the module. Pass it to
> > `instrumentModules`, then create the client with `new Anthropic.Anthropic()`.
>
> ### 4. Use Anthropic as usual
>
> ```typescript theme={null}
> // Make API calls to Anthropic as you normally would
> const response = await anthropic.messages.create({
>   model: "claude-sonnet-4-5",
>   max_tokens: 1024,
>   messages: [
>     { role: "user", content: "Hello, how are you?" }
>   ],
> });
>
> console.log(response.content);
> ```
>
> All Anthropic API calls are now automatically traced in Tracevell.

> [tab] Python
>
> ### 1. Install Tracevell and Anthropic
>
> ```bash theme={null}
> pip install -U 'lmnr[all]' anthropic python-dotenv
> ```
>
> ### 2. Set up your environment variables
>
> Store your API keys in a `.env` file:
>
> ```bash theme={null}
> # .env file
> LMNR_PROJECT_API_KEY=your-tracevell-project-api-key
> ANTHROPIC_API_KEY=your-anthropic-api-key
> ```
>
> > [!NOTE]
> >
> > To see an example of how to integrate Tracevell within a FastAPI application, check out our [FastAPI integration guide](https://tracevell.com/docs/guides/fastapi.md).
>
> ### 3. Initialize Tracevell
>
> Just add a single line at the start of your application or file to instrument Anthropic with Tracevell.
>
> ```python theme={null}
> from lmnr import Tracevell
> from anthropic import Anthropic
> import os
> from dotenv import load_dotenv
>
> # Load environment variables from .env file
> load_dotenv()
>
> # This single line instruments all Anthropic API calls
> Laminar.initialize()
>
> # Initialize Anthropic client as usual
> client = Anthropic()
> ```
>
> ### 4. Use Anthropic as usual
>
> ```python theme={null}
> # Make API calls to Anthropic as you normally would
> response = client.messages.create(
>     model="claude-sonnet-4-5",
>     max_tokens=1024,
>     messages=[
>         {"role": "user", "content": "Hello, how are you?"}
>     ]
> )
>
> print(response.content)
> ```
>
> All Anthropic API calls are now automatically traced in Tracevell.

## Monitoring Anthropic usage

After instrumenting your Anthropic calls with Tracevell, you'll be able to:

1. **View detailed traces** of each Anthropic API call, including request and response
2. **Track token usage and cost** across different models
3. **Monitor latency** and performance metrics
4. **Open LLM span in Playground** for prompt engineering
5. **Debug issues** with failed API calls or unexpected model outputs

Visit your Tracevell dashboard to view your Anthropic traces and analytics.

## Enrich your Anthropic traces

* Attach sessions, user IDs, metadata, and tags to Anthropic spans via the [SDK reference](https://tracevell.com/docs/sdk/reference).
* Wrap the functions around your Anthropic calls with `observe` and mark them as [TOOL spans](https://tracevell.com/docs/tracing/structure/span-types.md) so they show up in the transcript.

## Related integrations

> [card] [OpenAI](https://tracevell.com/docs/integrations/openai.md)
>
> Trace the OpenAI SDK directly in TypeScript and Python.

> [card] [Gemini](https://tracevell.com/docs/integrations/gemini.md)
>
> Trace Gemini calls made with the Google Gen AI SDK.

> [card] [OpenRouter](https://tracevell.com/docs/integrations/openrouter.md)
>
> Trace OpenRouter requests with model and cost attribution.

> [card] [Claude Agent SDK](https://tracevell.com/docs/integrations/claude-agent-sdk.md)
>
> Trace Claude Agent SDK runs and their subagents.

> [card] [Vercel AI SDK](https://tracevell.com/docs/integrations/vercel-ai-sdk.md)
>
> Trace `generateText` and `streamText` in Next.js and Node.js.

> [card] [All integrations](https://tracevell.com/docs/integrations.md)
>
> Browse every provider, framework, coding agent, and browser integration Tracevell supports.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.