Skip to main content
Automatically capture all Gemini model calls made through the google-genai SDK.

Setup

import traceroot
from traceroot import Integration

traceroot.initialize(integrations=[Integration.GOOGLE_GENAI])

Usage

Once initialized, all Gemini calls are captured automatically — including tool calls:
import os
from google import genai
from google.genai import types

client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])

weather_tool = types.Tool(function_declarations=[
    types.FunctionDeclaration(
        name="get_weather",
        description="Get current weather for a city",
        parameters=types.Schema(
            type="OBJECT",
            properties={"city": types.Schema(type="STRING", description="City name")},
            required=["city"],
        ),
    )
])

# This call is automatically traced
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="What's the weather in Tokyo?",
    config=types.GenerateContentConfig(tools=[weather_tool]),
)

print(response.text)

What Gets Captured

AttributeDescription
Modelgemini-2.5-flash, gemini-2.0-pro, etc.
ContentsInput messages
ResponseGenerated text and function calls
TokensInput and output token counts
CostCalculated from token usage and model pricing
LatencyRequest duration