Skip to main content
Python auto-instrumentation library for OpenAI’s Python SDK. The traces emitted by this instrumentation are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as Arize Phoenix.

Installation

Quickstart

This example shows how to instrument a program that uses OpenAI and observe the traces via Arize Phoenix.

Install packages

Start Phoenix server

The Phoenix server runs entirely on your machine and does not send data over the internet.

Setup instrumentation

Configure the OpenAIInstrumentor and set up the tracer to send traces to Phoenix:

Set API key

Run your application

Visit the Phoenix app at http://localhost:6006 to see your traces.

Example with context attributes

FAQ

Q: How to get token counts when streaming? A: To get token counts when streaming, install openai>=1.26 and set stream_options={"include_usage": True} when calling create. See the example shown above. For more info, see OpenAI’s announcement.

More Info