import * as KnowYourAI from '@know-your-ai/node';
import { GoogleGenAI } from '@google/genai';
// Initialize with all options
KnowYourAI.init({
dsn: process.env.KNOW_YOUR_AI_DSN!,
environment: 'production',
release: '1.2.0',
sampleRate: 1.0,
batchSize: 10,
flushInterval: 5000,
debug: false,
onCapture: (data) => {
console.log(`Captured: ${data.model} ${data.operation} (${data.duration}ms)`);
},
integrations: [
KnowYourAI.googleGenAIIntegration({
recordInputs: true,
recordOutputs: true,
recordRequestParams: true,
}),
],
});
// Instrument the client
const genAI = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY! });
const client = KnowYourAI.instrumentGoogleGenAIClient(genAI);
// Make AI calls — everything is tracked automatically
const response = await client.models.generateContent({
model: 'gemini-2.0-flash',
contents: 'What are the benefits of TypeScript?',
});
console.log(response.text);
// Ensure events are sent before exit
await KnowYourAI.getClient()?.flush();