@tozil/openai
v0.1.1
Published
Tozil instrumentation for the OpenAI SDK
Maintainers
Readme
@tozil/openai
Tozil instrumentation for the OpenAI SDK.
Automatically tracks every chat.completions.create() call — model, tokens, latency — with zero code changes to your OpenAI usage.
Install
npm install @tozil/core @tozil/openaiUsage
import { init } from "@tozil/core";
import { openai } from "@tozil/openai";
init({
apiKey: "tz_...",
instrumentations: [openai()],
});
// Use OpenAI as normal — tracking is automatic
import OpenAI from "openai";
const client = new OpenAI();
const completion = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello" }],
});How it works
The plugin monkey-patches chat.completions.create() on the OpenAI SDK prototype. It captures:
- Model name
- Input/output token counts (from
usagein the response) - Latency in milliseconds
- User and endpoint context (if set via
@tozil/core)
It does not capture prompts, completions, or any content.
Streaming support
Streaming with stream: true is fully supported. Token usage is captured from the final chunk's usage field.
License
MIT
