Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.lumiqtrace.com/llms.txt

Use this file to discover all available pages before exploring further.

Wrap your OpenAI client instance with wrapOpenAI(). Every call your existing code makes is traced automatically — no changes to call sites required.

Installation

npm install @lumiqtrace/sdk openai

Setup

import OpenAI from "openai";
import { lumiqtrace } from "@lumiqtrace/sdk";

lumiqtrace.init({ apiKey: process.env.LUMIQTRACE_API_KEY! });

const openai = lumiqtrace.wrapOpenAI(new OpenAI());
Pass the wrapped client to any function that makes OpenAI calls. The client is a drop-in replacement — its API is identical.

Example

const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Summarize this document." }],
});
LumiqTrace captures this call as a span with model, prompt tokens, completion tokens, latency, and cost.

What gets captured

FieldDetails
Modelgpt-4o, gpt-4o-mini, o1, etc.
Input tokensFrom usage.prompt_tokens
Output tokensFrom usage.completion_tokens
CostCalculated from token counts and OpenAI pricing
LatencyTotal time from request to response
Statussuccess or error with error message
Finish reasonstop, length, tool_calls, content_filter

Streaming

wrapOpenAI() supports streaming responses. Token counts are accumulated from the stream chunks.
const stream = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Write a poem." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

Embeddings

Embedding calls are traced with model, token count, and latency. Cost is calculated from the embedding model pricing.
const embedding = await openai.embeddings.create({
  model: "text-embedding-3-small",
  input: "The quick brown fox",
});
storePrompts must be true in lumiqtrace.init() to store prompt text alongside traces. Disabled by default for privacy.

Next steps