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

# Google GenAI Integration

ActGuard patches `google.genai` low-level API client methods and tracks `generateContent` usage.

## Requirements

| Requirement        | Version |
| ------------------ | ------- |
| `google-genai` SDK | `>=0.8` |
| Python             | `>=3.9` |

```bash theme={null}
pip install "google-genai>=0.8"
```

The repository example currently pins `google-genai>=1.47.0` in
`actguard/examples/30_google_adk/requirements.txt`.

## Patched methods

* `google.genai._api_client.BaseApiClient.request`
* `google.genai._api_client.BaseApiClient.request_streamed`
* `google.genai._api_client.BaseApiClient.async_request`
* `google.genai._api_client.BaseApiClient.async_request_streamed`

Budget tracking is applied to `:generateContent` and `:streamGenerateContent` paths.

## Usage with ActGuard runtime

```python theme={null}
import os
from google import genai
import actguard

client = actguard.Client.from_env()
genai_client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])

with client.run(user_id="alice", run_id="run-google"):
    with client.budget_guard(usd_limit=0.10) as guard:
        response = genai_client.models.generate_content(
            model="gemini-2.0-flash",
            contents="Explain retries in distributed systems",
        )

print(guard.tokens_used, guard.usd_used)
```

Model ids are normalized for pricing (for example `models/gemini-...` -> `gemini-...`).
