Skip to main content
Wrap your GoogleGenerativeAI client with wrapGoogle(). All generateContent and chat calls are traced automatically.

Installation

npm install @zespan/sdk @google/generative-ai

Setup

import { GoogleGenerativeAI } from "@google/generative-ai";
import { zespan } from "@zespan/sdk";

zespan.init({ apiKey: process.env.ZESPAN_API_KEY! });

const genAI = zespan.wrapGoogle(new GoogleGenerativeAI(process.env.GOOGLE_API_KEY!));

Example

const model = genAI.getGenerativeModel({ model: "gemini-2.5-flash" });

const result = await model.generateContent("Explain token pricing in two sentences.");
console.log(result.response.text());

What gets captured

FieldDetails
Modelgemini-2.5-flash, gemini-2.5-pro, etc.
Input tokensFrom usageMetadata.promptTokenCount
Output tokensFrom usageMetadata.candidatesTokenCount
CostCalculated from token counts and Google pricing
LatencyTotal request duration
Finish reasonSTOP, MAX_TOKENS, SAFETY, etc.

Chat sessions

const model = genAI.getGenerativeModel({ model: "gemini-2.5-flash" });
const chat = model.startChat();

const result = await chat.sendMessage("What is Zespan?");
console.log(result.response.text());
Each sendMessage call is traced as a separate span in the session.

Next steps