---
title: "OpenAI Tracing"
description: "Phoenix provides auto-instrumentation for the [OpenAI Python Library](https://github.com/openai/openai-python)."
---

import RegisterTracerPython from "../../../../snippets/register-tracer-python.mdx";

<Info>
**Note***: This instrumentation also works with Azure OpenAI

</Info>

## Install

```bash
pip install openinference-instrumentation-openai openai
```

## Setup

Add your OpenAI API key as an environment variable:

```shell
export OPENAI_API_KEY=[your_key_here]
```

<RegisterTracerPython projectName="my-llm-app" />

## Run OpenAI

```python
import openai

client = openai.OpenAI()
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a haiku."}],
)
print(response.choices[0].message.content)
```

## Observe

Now that you have tracing setup, all invocations of OpenAI (completions, chat completions, embeddings) will be streamed to your running Phoenix for observability and evaluation.

## Resources

* [Example notebook](https://github.com/Arize-ai/phoenix/blob/main/tutorials/tracing/openai_tracing_tutorial.ipynb)

* [OpenInference package](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-openai)

* [Working examples](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-openai/examples)


