OpenAI
cetra traces OpenAI chat completions, Responses API calls and embeddings, with their messages, tool calls, token counts and cost.
Install
Section titled “Install”pip install "cetra-sdk[openai]" openainpm install @cetra-ai/sdk @arizeai/openinference-instrumentation-openai openaiSet up
Section titled “Set up”Turn on the instrumentation when you start cetra, then call OpenAI as usual. The spans nest under your own spans and carry the session, user, tags and metadata of the current context.
import cetrafrom openai import OpenAI
cetra.init(instrument=["openai"])
client = OpenAI()client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": "What is the weather in Paris?"}],)
cetra.flush()import { init } from "@cetra-ai/sdk";import { openai } from "@cetra-ai/sdk/openai";import OpenAI from "openai";init({ apiKey: process.env.CETRA_API_KEY, instrument: [openai(OpenAI)] });const client = new OpenAI();await client.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: "What is the weather in Paris?" }],});What you get
Section titled “What you get”- Each chat completion and each Responses API call is an
llmspan with the provideropenai, the input and output as chat messages, and the tool definitions you passed. - A tool call in the answer shows as a tool call in the output messages. The tool result you send back shows in the next call’s input.
- Token counts include the cached input tokens when OpenAI reports them. cetra computes the cost from its price table.
- Streamed answers record the time to first token with the OpenInference and OpenLLMetry instrumentations. The streamed fixture of the official OpenTelemetry instrumentation has no time to first token.
- An embeddings call is an
embeddingspan with the input token count and a cost.
Limits
Section titled “Limits”- The fixtures were captured with the OpenAI Python SDK 3.45.0 and these instrumentations: OpenInference 0.1.69, OpenLLMetry 0.62.4 and the official
opentelemetry-instrumentation-openai-v22.4b0. Other versions are not covered. - Embedding vectors are not stored. Pass
capture_content=False(Python) orcaptureContent: falseto the helper and toinit(TypeScript) to keep prompts and answers out of cetra. - If you use another instrumentation library, see OpenInference, OpenLLMetry or OpenTelemetry GenAI.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Online rules: score these traces automatically.