@vaiuai/telemetry
v1.0.0
Published
Vaiu Telemetry SDK for tracking LLM traces, latency, and token usage.
Readme
@vaiuai/telemetry
Vaiu Telemetry SDK for Node.js and TypeScript applications. Instruments LLM calls, tracking model traces, latency, and token usage to send to Vaiu Telemetry.
Installation
npm install @vaiuai/telemetryQuick Start
Environment Variables
Set environment variables:
VAIU_API_HOST=https://your-telemetry-host.com
VAIU_API_PUBLIC_KEY=pk-vaiu-...
VAIU_API_SECRET_KEY=sk-vaiu-...Usage
import { VaiuTelemetry } from "@vaiuai/telemetry";
const client = new VaiuTelemetry(); // loads from env vars
// 1. Create a Trace
const trace = client.trace({
name: "chat-workflow",
userId: "user-123",
});
// 2. Start a Generation
const generation = trace.generation({
name: "openai-gpt-4o",
model: "gpt-4o",
input: "Hello, world!",
});
// ... call your model API ...
// 3. End Generation
generation.end({
output: "Hello! How can I help you today?",
usage: {
input: 10,
output: 15,
total: 25,
},
});
// 4. Flush Telemetry
await client.flushAsync();Convenient Helpers
// Observe async function
const result = await client.observe(
"doc-summary",
"gpt-4o-mini",
async () => {
return await myLlmCall();
},
(res) => ({
output: res.text,
usage: { input: res.promptTokens, output: res.completionTokens },
})
);
// One-shot generation logging
await client.logGeneration({
name: "completion",
model: "claude-3-5-sonnet",
latencyMs: 450,
promptTokens: 100,
completionTokens: 50,
input: "Prompt string",
output: "Completion string",
});