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

# Gemini

> Add HoneyHive observability to your Google Gemini applications

[Google Gemini](https://ai.google.dev/) provides multimodal AI models for chat, vision, and function calling. HoneyHive integrates with Gemini via the OpenInference instrumentor, automatically capturing all API calls, function calls, and token usage.

## Quick Start

<Tip>
  **Add HoneyHive tracing in just 4 lines of code.** Add this to your existing Gemini app and all generate calls, function calls, and chat sessions are automatically traced.
</Tip>

<Tip>
  To see where to initialize the tracer for your environment, including AWS Lambda and long-running servers, see [Tracer Initialization](/v2/tracing/tracer-initialization).
</Tip>

<Note>
  Requires `google-genai` 0.3.0 or later. The older `google-generativeai` package is not supported.
</Note>

```bash theme={null}
pip install "honeyhive[openinference-google-ai]"

# Or install separately
pip install honeyhive openinference-instrumentation-google-genai google-genai
```

```python theme={null}
import os
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.google_genai import GoogleGenAIInstrumentor

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)
GoogleGenAIInstrumentor().instrument(tracer_provider=tracer.provider)

# Your existing Gemini code works unchanged
```

## What Gets Traced

The instrumentor automatically captures:

* **Content generation** - `client.models.generate_content()` with inputs, outputs, and token usage
* **Function calls** - Each function call with arguments and results
* **Chat sessions** - `chat.send_message()` with conversation history
* **Streaming responses** - Streamed generations with aggregated tokens

No manual instrumentation required.

***

## Example: Content Generation

```python theme={null}
import os
from google import genai
from google.genai import types
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.google_genai import GoogleGenAIInstrumentor

tracer = HoneyHiveTracer.init(project="your-project")
GoogleGenAIInstrumentor().instrument(tracer_provider=tracer.provider)

client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))

# Simple content generation
response = client.models.generate_content(
    model="gemini-2.0-flash",
    contents="What is the capital of France?",
    config=types.GenerateContentConfig(max_output_tokens=100),
)
print(response.text)

# Chat session - also traced
chat = client.chats.create(model="gemini-2.0-flash")
chat_response = chat.send_message("Tell me a fun fact about Paris.")
print(chat_response.text)
```

***

## Environment Configuration

```bash theme={null}
# HoneyHive configuration
export HH_API_KEY="your-honeyhive-api-key"
export HH_PROJECT="your-project"

# Google AI configuration
export GOOGLE_API_KEY="your-google-ai-api-key"
```

***

## Troubleshooting

### Traces not appearing

1. **Check environment variables** - Ensure `HH_API_KEY` and `HH_PROJECT` are set
2. **Pass the tracer provider** - The instrumentor must receive `tracer_provider=tracer.provider`:

```python theme={null}
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.google_genai import GoogleGenAIInstrumentor

tracer = HoneyHiveTracer.init(project="your-project")

# ✅ Correct - pass tracer_provider
GoogleGenAIInstrumentor().instrument(tracer_provider=tracer.provider)

# ❌ Wrong - missing tracer_provider
GoogleGenAIInstrumentor().instrument()
```

3. **Initialize before making calls** - Call `instrument()` before creating the `genai.Client`

### SDK version

The instrumentor works with the newer `google-genai` SDK. If you're using the older `google-generativeai` package, migrate to `google-genai`:

```bash theme={null}
# Newer SDK (recommended)
pip install google-genai openinference-instrumentation-google-genai

# Import pattern
from google import genai
from openinference.instrumentation.google_genai import GoogleGenAIInstrumentor
```

***

## Related

<CardGroup cols={2}>
  <Card title="Google ADK" icon="code" href="/v2/integrations/google-adk">
    Google Agent Development Kit integration
  </Card>

  <Card title="Enrich Your Traces" icon="sparkles" href="/v2/tutorials/enriching-traces">
    Add user IDs and custom metadata to traces
  </Card>

  <Card title="Distributed Tracing" icon="share-nodes" href="/v2/tutorials/distributed-tracing">
    Trace calls across service boundaries
  </Card>
</CardGroup>

***

## Resources

* [Google AI Documentation](https://ai.google.dev/docs)
* [OpenInference Google GenAI Instrumentor](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-google-genai)
