OpenAI
Trace the OpenAI SDK in Python and TypeScript.
Wrap the OpenAI client and chat.completions.create and responses.create calls are captured as LLM spans with the prompt, response, token counts, and model. In Python, embeddings.create is also traced (as an EMBEDDING span).
Prerequisites
pip install -U "neatlogs[openai]" openaiUsage
import os
import neatlogs
from openai import OpenAI
neatlogs.init(api_key=os.environ["NEATLOGS_API_KEY"], workflow_name="openai-demo")
client = neatlogs.wrap(OpenAI())
resp = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "In one sentence, what is OpenAI?"}],
)
print(resp.choices[0].message.content)
neatlogs.flush()
neatlogs.shutdown()That's the whole setup — wrap() opens a WORKFLOW root for you, so this renders in the dashboard with no extra wrapper. Streaming and async clients (AsyncOpenAI) are traced too, and token counts are recorded even for streamed responses.
Making several calls in one run? Group them into one trace with a
WORKFLOWroot.
TypeScript alternative: instead of
wrapOpenAI, you can passinstrumentations: ['openai']toinit()and import the SDK afterward. See the TypeScript SDK.