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

# Google Gemini

> Auto-track all Google Gemini API calls

## Installation

```bash theme={null}
pip install meshai-sdk[gemini]
```

## Usage

```python theme={null}
from meshai import MeshAI
from meshai.integrations.gemini import wrap_gemini
from google import genai

client = MeshAI(api_key="msh_...", agent_name="my-agent")
client.register(framework="custom", model_provider="google")

# Wrap the Gemini client
gem = wrap_gemini(genai.Client(), meshai=client)

# Use as normal, all calls auto-tracked
response = gem.models.generate_content(
    model="gemini-2.0-flash",
    contents="Hello",
)
# Model, input/output tokens captured automatically

# Works with different models too:
response = gem.models.generate_content(
    model="gemini-2.5-pro",
    contents="Explain AI governance",
)
```

## How It Works

`wrap_gemini` wraps the Google Gen AI client's `generate_content` method. After each call, it:

1. Extracts the **model name** from the response `usage_metadata`
2. Extracts **input and output token counts** from `usage_metadata`
3. Sends the usage event to MeshAI (buffered, non-blocking)

Works with both the new unified `google-genai` SDK and the legacy `google-generativeai` SDK.

## Alternative: Proxy (Zero-Code)

There is no dedicated Gemini proxy route. Gemini traffic can be routed
through the proxy's Vertex AI provider instead, using the Vertex path
format, which requires the location and project in the URL:

```
https://proxy.meshai.dev/v1/vertex/k/msh_YOUR_PROXY_KEY/{location}/{project}/publishers/google/models/{model}:generateContent
```

For example:

```
https://proxy.meshai.dev/v1/vertex/k/msh_YOUR_PROXY_KEY/us-central1/my-project/publishers/google/models/gemini-2.0-flash:generateContent
```

This requires a Vertex AI project and Google Cloud credentials (a bearer
token from ADC or a service account), not a plain Gemini API key.
