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

# Gemini Integration

> Automatically track Google Gemini API calls

The SDK provides seamless instrumentation for the Google Gemini Python client.

## Setup

Enable instrumentation with a single function call. This will automatically track all subsequent calls to `GenerativeModel`.

```python theme={null}
import agentbasis
from agentbasis.llms.gemini import instrument

# Initialize AgentBasis first
agentbasis.init(api_key="your-api-key", agent_id="your-agent-id")

# Enable Gemini instrumentation
instrument()
```

## Usage

Once instrumented, use the Gemini client as you normally would. The SDK automatically captures:

* Model name
* Input prompts
* Generated content
* Token usage
* Latency

### Synchronous

```python theme={null}
import google.generativeai as genai

genai.configure(api_key="your-gemini-api-key")

model = genai.GenerativeModel("gemini-pro")
response = model.generate_content("Explain quantum computing in simple terms")

print(response.text)
```

### Asynchronous

```python theme={null}
import google.generativeai as genai
import asyncio

genai.configure(api_key="your-gemini-api-key")

async def main():
    model = genai.GenerativeModel("gemini-pro")
    response = await model.generate_content_async("Explain quantum computing")
    print(response.text)

asyncio.run(main())
```

## Streaming

Streaming responses are also supported and will be fully tracked once the stream completes.

```python theme={null}
model = genai.GenerativeModel("gemini-pro")

response = model.generate_content("Tell me a story", stream=True)

for chunk in response:
    print(chunk.text, end="")
```

## Captured Data

The integration automatically records:

| Field                        | Description                     |
| ---------------------------- | ------------------------------- |
| `gen_ai.system`              | `gemini`                        |
| `gen_ai.request.model`       | Model name (e.g., `gemini-pro`) |
| `gen_ai.prompt`              | Input prompt text               |
| `gen_ai.completion`          | Generated response              |
| `gen_ai.usage.input_tokens`  | Prompt token count              |
| `gen_ai.usage.output_tokens` | Completion token count          |
| `duration`                   | Request latency                 |
