> ## Documentation Index
> Fetch the complete documentation index at: https://traceroot.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Gemini

> Auto-instrument Google Gemini API calls via the GenAI SDK

Automatically capture all Gemini model calls made through the `google-genai` SDK.

## Setup

```python theme={null}
import traceroot
from traceroot import Integration

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

## Usage

Once initialized, all Gemini calls are captured automatically — including tool calls:

```python theme={null}
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

| Attribute | Description                                   |
| --------- | --------------------------------------------- |
| Model     | `gemini-2.5-flash`, `gemini-2.0-pro`, etc.    |
| Contents  | Input messages                                |
| Response  | Generated text and function calls             |
| Tokens    | Input and output token counts                 |
| Cost      | Calculated from token usage and model pricing |
| Latency   | Request duration                              |

## Run the example

Clone the repo and run a complete agent end-to-end.

<Card title="Python" icon="python" href="https://github.com/traceroot-ai/traceroot/tree/main/examples/python/gemini-tool-agent">
  Run the Python example
</Card>
