O

OpenAI

Wrap the official OpenAI SDK in TypeScript or Python. Chat completions, the Responses API, streams, and embeddings traced with tokens and cost.

Built by

telemetry.dev

Language

TypeScript + Python

Packages

@telemetry-dev/openai · telemetry-dev-openai

Category

Model providers

About the OpenAI integration

@telemetry-dev/openai (TypeScript) and telemetry-dev-openai (Python) wrap the official OpenAI SDKs. Wrap a single client or instrument globally — every chat.completions.create, responses.create, and embeddings.create call becomes a span with the native OpenAI request and response shapes, token usage, and latency. Azure OpenAI clients are detected and recorded with the azure.ai.openai provider.

Key features

  • Chat Completions and Responses API: Both surfaces are traced, including parse and stream helpers that route through create.
  • Streaming with usage: Streamed responses are traced end to end; opt into injectStreamUsage to capture token usage without changing what your code sees.
  • Embeddings: Embedding calls record model, input, and token usage — vectors are intentionally never captured.
  • Per-client or global: wrapOpenAI(client) for explicit control, or instrumentOpenAI() once at startup for every client.
  • Fail-open: Without an API key the wrapper is a silent no-op; instrumentation errors never reach your code.

Get started

Install alongside the core SDK and wrap your client:

import OpenAI from "openai";
import { init } from "@telemetry-dev/sdk";
import { wrapOpenAI } from "@telemetry-dev/openai";

init({ apiKey: process.env.TELEMETRY_DEV_API_KEY });

const openai = wrapOpenAI(new OpenAI());
await openai.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Say hello" }],
});

The same shape works in Python:

import telemetry_dev
from openai import OpenAI
from telemetry_dev_openai import wrap_openai

telemetry_dev.init()  # reads TELEMETRY_DEV_API_KEY

client = wrap_openai(OpenAI())
client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Say hello"}],
)

Prefer app-wide instrumentation? Call instrumentOpenAI() / instrument_openai() once during startup instead of wrapping each client.