{"library":"openinference-instrumentation-anthropic","title":"OpenInference Anthropic Instrumentation","description":"openinference-instrumentation-anthropic is a Python auto-instrumentation library for the Anthropic package. It captures traces for Anthropic client calls (e.g., Messages, Completions, AsyncMessages, AsyncCompletions, BetaMessagesParse) and aligns them with OpenInference semantic conventions. These traces are fully OpenTelemetry compatible and can be sent to any OpenTelemetry collector, such as Arize Phoenix, for observability and evaluation. The library is currently at version 1.0.0 and is actively maintained with frequent updates to the broader OpenInference project.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install openinference-instrumentation-anthropic anthropic opentelemetry-sdk opentelemetry-exporter-otlp"],"cli":null},"imports":["from openinference.instrumentation.anthropic import AnthropicInstrumentor"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom anthropic import Anthropic\nfrom openinference.instrumentation.anthropic import AnthropicInstrumentor\nfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\nfrom opentelemetry.sdk import trace as trace_sdk\nfrom opentelemetry.sdk.trace.export import SimpleSpanProcessor\n\n# Set your Anthropic API key (replace with actual key or use environment variable)\nos.environ['ANTHROPIC_API_KEY'] = os.environ.get('ANTHROPIC_API_KEY', 'your_anthropic_api_key_here')\n\n# Configure OpenTelemetry TracerProvider to send traces to an OTLP endpoint (e.g., Arize Phoenix)\n# Default Phoenix endpoint: http://localhost:6006/v1/traces\nendpoint = os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://127.0.0.1:6006/v1/traces')\n\ntracer_provider = trace_sdk.TracerProvider()\ntracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))\n\n# Instrument the Anthropic client\nAnthropicInstrumentor().instrument(tracer_provider=tracer_provider)\n\n# Create an Anthropic client and make a request\nclient = Anthropic()\n\ntry:\n    print(\"Making Anthropic API call...\")\n    message = client.messages.create(\n        model=\"claude-3-5-sonnet-20240620\",\n        max_tokens=1000,\n        temperature=0,\n        messages=[\n            {\"role\": \"user\", \"content\": \"Explain the concept of quantum entanglement in simple terms.\"}\n        ]\n    )\n    print(\"Anthropic Response:\")\n    print(message.content[0].text)\n    print(\"Traces should now be visible in your OpenTelemetry collector (e.g., Phoenix).\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure ANTHROPIC_API_KEY is set and your OpenTelemetry collector is running.\")\n","lang":"python","description":"This quickstart demonstrates how to instrument Anthropic API calls using `openinference-instrumentation-anthropic` and send the traces to an OpenTelemetry collector. It configures a `TracerProvider` with an OTLP HTTP exporter, instruments the Anthropic library, and then makes a sample API call. You can run a local collector like Arize Phoenix (<code>python -m phoenix.server.main serve</code>) to view the traces.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"1.0.0","pypi_latest":"1.0.4","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":8.4,"avg_import_s":0.7,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.56,"mem_mb":16.3,"disk_size":"76.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":9.5,"import_time_s":0.41,"mem_mb":16.3,"disk_size":"73M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.78,"mem_mb":17.4,"disk_size":"81.9M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":8.2,"import_time_s":0.69,"mem_mb":17.4,"disk_size":"79M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.91,"mem_mb":17.6,"disk_size":"73.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":6.5,"import_time_s":0.89,"mem_mb":17.6,"disk_size":"70M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.89,"mem_mb":15.6,"disk_size":"72.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":7,"import_time_s":0.85,"mem_mb":15.6,"disk_size":"69M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.5,"mem_mb":15.8,"disk_size":"75.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"openinference-instrumentation-anthropic","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":10.8,"import_time_s":0.5,"mem_mb":15.8,"disk_size":"72M"}]}}