Skip to main content

Documentation Index

Fetch the complete documentation index at: https://langwatch.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

LangWatch integrates with Anthropic through OpenInference instrumentation to capture detailed information about your Claude API calls.

Installation

pip install langwatch anthropic openinference-instrumentation-anthropic

Usage

The LangWatch API key is configured by default via the LANGWATCH_API_KEY environment variable.
Use the OpenInference instrumentation for Anthropic by passing AnthropicInstrumentor to langwatch.setup().
import langwatch
from anthropic import Anthropic
import os

from openinference.instrumentation.anthropic import AnthropicInstrumentor

langwatch.setup(instrumentors=[AnthropicInstrumentor()])

client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))


@langwatch.trace(name="Anthropic Call with Community Instrumentor")
def generate_text_with_community_instrumentor(prompt: str):
    response = client.messages.create(
        model="claude-sonnet-4-5-20250929",
        max_tokens=1024,
        messages=[{"role": "user", "content": prompt}],
    )
    return response.content[0].text


if __name__ == "__main__":
    user_query = "Tell me a joke"
    response = generate_text_with_community_instrumentor(user_query)
    print(f"User: {user_query}")
    print(f"AI: {response}")
The AnthropicInstrumentor automatically captures all Anthropic API calls globally once instrumented. Use @langwatch.trace() to create a parent trace under which API calls will be nested.