Name | openinference-instrumentation-anthropic JSON |
Version |
0.1.10
JSON |
| download |
home_page | None |
Summary | OpenInference Anthropic Instrumentation |
upload_time | 2025-02-04 23:10:55 |
maintainer | None |
docs_url | None |
author | None |
requires_python | <3.14,>=3.9 |
license | None |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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.14,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "OpenInference Authors <oss@arize.com>",
"download_url": "https://files.pythonhosted.org/packages/7a/6c/483d06494ec61435214f510ae36381bc6fe7724fe8b5555ed1efcf12ed94/openinference_instrumentation_anthropic-0.1.10.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.10",
"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": "e633a6676e12c58345c83ad7072cede27e9c49a6a74ea8377ee6131b472252e4",
"md5": "1ef019de2725e8ee8d17641b94168fe6",
"sha256": "45e38b0fd4dd4d5b4aaff53869ad44745362025d56bdcdb7c7224877e33ff77e"
},
"downloads": -1,
"filename": "openinference_instrumentation_anthropic-0.1.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1ef019de2725e8ee8d17641b94168fe6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.14,>=3.9",
"size": 16349,
"upload_time": "2025-02-04T23:10:52",
"upload_time_iso_8601": "2025-02-04T23:10:52.523979Z",
"url": "https://files.pythonhosted.org/packages/e6/33/a6676e12c58345c83ad7072cede27e9c49a6a74ea8377ee6131b472252e4/openinference_instrumentation_anthropic-0.1.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "7a6c483d06494ec61435214f510ae36381bc6fe7724fe8b5555ed1efcf12ed94",
"md5": "42f8175a1875124a6e6be8114decc44e",
"sha256": "a71e9ae7ff729b088bc80de0a01d320adc1b38888824450e1ade4bdccdca9b50"
},
"downloads": -1,
"filename": "openinference_instrumentation_anthropic-0.1.10.tar.gz",
"has_sig": false,
"md5_digest": "42f8175a1875124a6e6be8114decc44e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.14,>=3.9",
"size": 13533,
"upload_time": "2025-02-04T23:10:55",
"upload_time_iso_8601": "2025-02-04T23:10:55.711677Z",
"url": "https://files.pythonhosted.org/packages/7a/6c/483d06494ec61435214f510ae36381bc6fe7724fe8b5555ed1efcf12ed94/openinference_instrumentation_anthropic-0.1.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-04 23:10:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Arize-ai",
"github_project": "openinference",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "openinference-instrumentation-anthropic"
}