# CometAPI Trace CometAPI calls with cetra through the OpenAI client. Trace CometAPI calls with cetra through the OpenAI client. ## Install **Python** ```bash pip install "cetra-sdk[openai]" openai ``` **TypeScript** ```bash npm install @cetra-ai/sdk @arizeai/openinference-instrumentation-openai openai ``` ## Set up **Python** ```python import os import cetra from openai import OpenAI cetra.init(instrument=["openai"]) client = OpenAI(base_url="https://api.cometapi.com/v1", api_key=os.environ["COMETAPI_KEY"]) response = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": "What is the capital of France?"}], ) print(response.choices[0].message.content) cetra.flush() ``` **TypeScript** ```ts import { init } from "@cetra-ai/sdk"; import { openai } from "@cetra-ai/sdk/openai"; import OpenAI from "openai"; ``` ```ts init({ apiKey: process.env.CETRA_API_KEY, instrument: [openai(OpenAI)] }); ``` ```ts const client = new OpenAI({ baseURL: "https://api.cometapi.com/v1", apiKey: process.env.COMETAPI_KEY }); await client.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: "What is the capital of France?" }], }); ``` ## What you get - Each chat completion is an `llm` span with the provider `cometapi`. - Input and output token counts come from the response. - No built-in price: add a custom model price in Settings → Model prices to get a cost. - With `cetra.init(instrument=["openai"])`, the endpoint host is in `server.address`, and cetra names the provider from it. ## Limits - CometAPI resells many publishers' models; the span names CometAPI, and the built-in prices do not apply. - No spans of CometAPI are captured in the repository. cetra maps the host `api.cometapi.com` to the provider `cometapi`. - The built-in prices have no CometAPI rows, so cost is empty until you add a custom model price in Settings → Model prices. - With plain OpenInference or the official OpenAI instrumentation in Python, the provider shows as `openai`: they do not record the endpoint. Use `cetra.init(instrument=["openai"])` or OpenLLMetry. - If a field is missing, look at the span's **Attributes** tab and compare it with [Span attributes](https://cetra.sh/docs/reference/attributes/). ## Next - [Traces](https://cetra.sh/docs/tracing/traces/): read the trace as a tree and a timeline. - [Cost and tokens](https://cetra.sh/docs/tracing/cost-and-tokens/): how cost is computed from the token counts. - [Custom model prices](https://cetra.sh/docs/tracing/cost-and-tokens/#custom-model-prices): price a model the built-in prices do not cover.