# OpenInference Anthropic Instrumentation
Python autoinstrumentation library for the [Anthropic](https://www.anthropic.com/api) package
This package implements the following Anthropic clients:
- `Messages`
- `Completions`
- `AsyncMessages`
- `AsyncCompletions`
These traces are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as [Arize `phoenix`](https://github.com/Arize-ai/phoenix).
## Installation
```shell
pip install openinference-instrumentation-anthropic
```
## Quickstart
Through your *terminal*, install required packages.
```shell
pip install openinference-instrumentation-anthropic anthropic arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp
```
You can start Phoenix with the following terminal command:
```shell
python -m phoenix.server.main serve
````
By default, Phoenix listens on `http://localhost:6006`. You can visit the app via a browser at the same address. (Phoenix does not send data over the internet. It only operates locally on your machine.)
Try the following code in a *Python file*.
1. Set up `AnthropicInstrumentor` to trace your application and sends the traces to Phoenix.
2. Then, set your Anthropic API key as an environment variable.
3. Lastly, create a Anthropic client, make a request, then go see your results in Phoenix at `http://localhost:6006`!
```python
import os
from anthropic import Anthropic
from openinference.instrumentation.anthropic import AnthropicInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
# Configure AnthropicInstrumentor with Phoenix endpoint
endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = trace_sdk.TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
AnthropicInstrumentor().instrument(tracer_provider=tracer_provider)
os.environ["ANTHROPIC_API_KEY"] = "YOUR_KEY_HERE"
client = Anthropic()
response = client.messages.create(
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Tell me about the history of Iceland!",
}
],
model="claude-3-opus-20240229",
)
print(response)
```
Now, on the Phoenix UI on your browser, you should see the traces from your Anthropic application. Click on a trace, then the "Attributes" tab will provide you with in-depth information regarding execution!
Raw data
{
"_id": null,
"home_page": null,
"name": "openinference-instrumentation-anthropic",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.15,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "OpenInference Authors <oss@arize.com>",
"download_url": "https://files.pythonhosted.org/packages/ca/62/40a4ae94a7a3e46a50f2d277b9e0d7de7ded77256c104bc1c23501852228/openinference_instrumentation_anthropic-0.1.20.tar.gz",
"platform": null,
"description": "# OpenInference Anthropic Instrumentation\n\nPython autoinstrumentation library for the [Anthropic](https://www.anthropic.com/api) package\n\nThis package implements the following Anthropic clients:\n- `Messages`\n- `Completions`\n- `AsyncMessages`\n- `AsyncCompletions`\n\nThese traces are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as [Arize `phoenix`](https://github.com/Arize-ai/phoenix).\n\n\n## Installation\n\n```shell\npip install openinference-instrumentation-anthropic\n```\n\n## Quickstart\n\nThrough your *terminal*, install required packages.\n\n```shell\npip install openinference-instrumentation-anthropic anthropic arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp\n```\n\nYou can start Phoenix with the following terminal command:\n```shell\npython -m phoenix.server.main serve\n````\nBy default, Phoenix listens on `http://localhost:6006`. You can visit the app via a browser at the same address. (Phoenix does not send data over the internet. It only operates locally on your machine.)\n\n\nTry the following code in a *Python file*.\n\n1. Set up `AnthropicInstrumentor` to trace your application and sends the traces to Phoenix. \n2. Then, set your Anthropic API key as an environment variable. \n3. Lastly, create a Anthropic client, make a request, then go see your results in Phoenix at `http://localhost:6006`!\n\n```python\nimport 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# Configure AnthropicInstrumentor with Phoenix endpoint\nendpoint = \"http://127.0.0.1:6006/v1/traces\"\ntracer_provider = trace_sdk.TracerProvider()\ntracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))\n\nAnthropicInstrumentor().instrument(tracer_provider=tracer_provider)\n\nos.environ[\"ANTHROPIC_API_KEY\"] = \"YOUR_KEY_HERE\"\n\nclient = Anthropic()\n\nresponse = client.messages.create(\n max_tokens=1024,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Tell me about the history of Iceland!\",\n }\n ],\n model=\"claude-3-opus-20240229\",\n)\nprint(response)\n```\n\nNow, on the Phoenix UI on your browser, you should see the traces from your Anthropic application. Click on a trace, then the \"Attributes\" tab will provide you with in-depth information regarding execution!\n",
"bugtrack_url": null,
"license": null,
"summary": "OpenInference Anthropic Instrumentation",
"version": "0.1.20",
"project_urls": {
"Homepage": "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-anthropic"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "7a975987b3e0491eb850a090cd5c82abc049fd5805ca0d43469a712ec352edbd",
"md5": "9fa7eaef677a2bcbe775a418aca09319",
"sha256": "f6dba468d7ae13296bbe221cd6968f98bc4760f62c45080e2de434ca6adc0a54"
},
"downloads": -1,
"filename": "openinference_instrumentation_anthropic-0.1.20-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9fa7eaef677a2bcbe775a418aca09319",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.15,>=3.9",
"size": 17391,
"upload_time": "2025-10-10T03:48:51",
"upload_time_iso_8601": "2025-10-10T03:48:51.137092Z",
"url": "https://files.pythonhosted.org/packages/7a/97/5987b3e0491eb850a090cd5c82abc049fd5805ca0d43469a712ec352edbd/openinference_instrumentation_anthropic-0.1.20-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ca6240a4ae94a7a3e46a50f2d277b9e0d7de7ded77256c104bc1c23501852228",
"md5": "e0a150696c8260dfb7fc8b319931ac9c",
"sha256": "d5339dffb100ad32bb7de9948386574e73af5ffdbcab4a4ebfa3d55c22256096"
},
"downloads": -1,
"filename": "openinference_instrumentation_anthropic-0.1.20.tar.gz",
"has_sig": false,
"md5_digest": "e0a150696c8260dfb7fc8b319931ac9c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.15,>=3.9",
"size": 14265,
"upload_time": "2025-10-10T03:48:53",
"upload_time_iso_8601": "2025-10-10T03:48:53.491293Z",
"url": "https://files.pythonhosted.org/packages/ca/62/40a4ae94a7a3e46a50f2d277b9e0d7de7ded77256c104bc1c23501852228/openinference_instrumentation_anthropic-0.1.20.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-10 03:48:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Arize-ai",
"github_project": "openinference",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "openai",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "grpcio",
"specs": [
[
">=",
"1.60.0"
]
]
},
{
"name": "opentelemetry-api",
"specs": [
[
">=",
"1.22.0"
]
]
},
{
"name": "opentelemetry-sdk",
"specs": [
[
">=",
"1.22.0"
]
]
},
{
"name": "opentelemetry-instrumentation-openai",
"specs": [
[
">=",
"0.40b0"
]
]
},
{
"name": "opentelemetry-instrumentation-langchain",
"specs": [
[
">=",
"0.40b0"
]
]
},
{
"name": "opentelemetry-exporter-otlp-proto-grpc",
"specs": [
[
">=",
"1.22.0"
]
]
},
{
"name": "langchain",
"specs": [
[
">=",
"0.1.0"
]
]
},
{
"name": "langgraph",
"specs": [
[
">=",
"0.0.15"
]
]
},
{
"name": "typing-extensions",
"specs": [
[
">=",
"4.8.0"
]
]
},
{
"name": "phoenix-client",
"specs": [
[
">=",
"0.1.0"
]
]
},
{
"name": "openinference-instrumentation-openllmetry",
"specs": [
[
">=",
"0.1.0"
]
]
}
],
"lcname": "openinference-instrumentation-anthropic"
}