Installation
npm install @fallom/trace @google/generative-ai
Quick Start
import fallom from "@fallom/trace";
import { GoogleGenerativeAI } from "@google/generative-ai";
// Initialize Fallom once at app startup
await fallom.init({ apiKey: process.env.FALLOM_API_KEY });
// Create a session for this conversation/request
const session = fallom.session({
configKey: "my-app",
sessionId: "session-123",
customerId: "user-456",
});
// Create and wrap the model
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY!);
const model = session.wrapGoogleAI(
genAI.getGenerativeModel({ model: "gemini-1.5-pro" })
);
// Use as normal - automatically traced!
const result = await model.generateContent("Hello!");
console.log(result.response.text());
With System Instruction
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY!);
const model = session.wrapGoogleAI(
genAI.getGenerativeModel({
model: "gemini-1.5-pro",
systemInstruction: "You are a helpful assistant.",
})
);
const result = await model.generateContent("Tell me about TypeScript.");
Chat Sessions
const chat = model.startChat({
history: [
{ role: "user", parts: [{ text: "Hello!" }] },
{ role: "model", parts: [{ text: "Hi there! How can I help?" }] },
],
});
// Each message is traced
const result = await chat.sendMessage("What's the weather like?");
Streaming
const result = await model.generateContentStream("Write a poem about coding.");
for await (const chunk of result.stream) {
process.stdout.write(chunk.text());
}
Model A/B Testing
import fallom from "@fallom/trace";
import { GoogleGenerativeAI } from "@google/generative-ai";
await fallom.init({ apiKey: "your-fallom-api-key" });
const session = fallom.session({
configKey: "my-experiment",
sessionId: "session-123",
});
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY!);
// Get assigned model for this session
const modelId = await session.getModel({ fallback: "gemini-1.5-flash" });
const model = session.wrapGoogleAI(genAI.getGenerativeModel({ model: modelId }));
const result = await model.generateContent("Hello!");
What Gets Traced
| Field | Description |
|---|---|
| Model | gemini-1.5-pro, gemini-1.5-flash |
| Duration | Total request time (ms) |
| Tokens | Input, output tokens |
| Cost | Calculated from token usage |
| Prompts | Input content |
| Completions | Model response |
| Session | Your config key + session ID |
Next Steps
Model A/B Testing
Compare Gemini models in production.
Vercel AI SDK
Use Gemini with Vercel AI SDK.

