O
Integration
OpenAI
Automatic tracing for OpenAI API calls including GPT-4o, GPT-4, o1, embeddings, and function calling.
Prerequisites
- OpenAI API key
- Lanternfish SDK installed
1
Install the SDK
bash
pip install "lanternfish[openai]"2
Initialize with auto-instrument
python
import os
import lanternfish
from openai import OpenAI
# Simply call instrument() and OpenAI is auto-traced!
lanternfish.instrument(
api_key=os.environ["LANTERNFISH_API_KEY"],
endpoint=os.environ["LANTERNFISH_ENDPOINT"],
)
client = OpenAI()3
Use as normal — tracing is automatic
python
# OpenAI calls are automatically traced and captured in your dashboard
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Book a flight to London"}
],
temperature=0.7,
)
# Captures: model name, tokens, latency, cost, and safety configurations
print(response.choices[0].message.content)What Lanternfish captures
- Complete trace timeline
- Token usage and cost
- Latency metrics
- Tool and function calls
- Error tracking
- Model information