> ## Documentation Index
> Fetch the complete documentation index at: https://docs.honeyhive.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI

> Add HoneyHive observability to your OpenAI applications

[OpenAI](https://platform.openai.com/docs) provides GPT models for chat completions, embeddings, and more. HoneyHive integrates with OpenAI via the OpenInference instrumentor, automatically capturing all API calls, tool use, and token usage.

## Quick Start

<Tip>
  **Add HoneyHive tracing in just 4 lines of code.** Add this to your existing OpenAI app and all chat completions, tool calls, and embeddings are automatically traced.
</Tip>

<Tip>
  To see where to initialize the tracer for your environment, including AWS Lambda and long-running servers, see [Tracer Initialization](/v2/tracing/tracer-initialization).
</Tip>

<Note>
  Last tested with `openai 2.30.0` (April 2026).
</Note>

```bash theme={null}
pip install "honeyhive[openinference-openai]"

# Or install separately
pip install honeyhive openinference-instrumentation-openai openai
```

```python theme={null}
import os
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.openai import OpenAIInstrumentor

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)
OpenAIInstrumentor().instrument(tracer_provider=tracer.provider)

# Your existing OpenAI code works unchanged
```

## What Gets Traced

The instrumentor automatically captures:

* **Chat completions** - `client.chat.completions.create()` with inputs, outputs, and token usage
* **Tool / function calls** - Each tool call with arguments and results
* **Embeddings** - `client.embeddings.create()` requests
* **Streaming responses** - Streamed completions with aggregated tokens

No manual instrumentation required.

***

## Example: Chat Completion

```python theme={null}
import openai
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.openai import OpenAIInstrumentor

tracer = HoneyHiveTracer.init(project="your-project")
OpenAIInstrumentor().instrument(tracer_provider=tracer.provider)

client = openai.OpenAI()

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the capital of France?"},
    ],
    max_tokens=50,
)
print(response.choices[0].message.content)

# A follow-up call - also traced
response2 = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": "Tell me a fun fact about Paris."},
    ],
    max_tokens=100,
)
print(response2.choices[0].message.content)
```

***

## Environment Configuration

```bash theme={null}
# HoneyHive configuration
export HH_API_KEY="your-honeyhive-api-key"
export HH_PROJECT="your-project"

# OpenAI configuration
export OPENAI_API_KEY="your-openai-api-key"
```

***

## Troubleshooting

### Traces not appearing

1. **Check environment variables** - Ensure `HH_API_KEY` and `HH_PROJECT` are set
2. **Pass the tracer provider** - The instrumentor must receive `tracer_provider=tracer.provider`:

```python theme={null}
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.openai import OpenAIInstrumentor

tracer = HoneyHiveTracer.init(project="your-project")

# ✅ Correct - pass tracer_provider
OpenAIInstrumentor().instrument(tracer_provider=tracer.provider)

# ❌ Wrong - missing tracer_provider
OpenAIInstrumentor().instrument()
```

3. **Initialize before making calls** - Call `instrument()` before creating the OpenAI client

***

## Related

<CardGroup cols={2}>
  <Card title="Enrich Your Traces" icon="sparkles" href="/v2/tutorials/enriching-traces">
    Add user IDs and custom metadata to traces
  </Card>

  <Card title="Custom Spans" icon="code" href="/v2/tracing/custom-spans">
    Create spans for business logic around API calls
  </Card>

  <Card title="Distributed Tracing" icon="share-nodes" href="/v2/tutorials/distributed-tracing">
    Trace calls across service boundaries
  </Card>
</CardGroup>

***

## Resources

* [OpenAI API Documentation](https://platform.openai.com/docs)
* [OpenInference OpenAI Instrumentor](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-openai)
