AgentOps provides seamless integration with Google’s Generative AI API, allowing you to monitor and analyze all your Gemini model interactions automatically.

Installation

pip install agentops google-genai

Setting Up API Keys

Before using Google Gemini with AgentOps, you need to set up your API keys. You can obtain:

Then to set them up, you can either export them as environment variables or set them in a .env file.

export GOOGLE_API_KEY="your_google_api_key_here"
export AGENTOPS_API_KEY="your_agentops_api_key_here"

Then load the environment variables in your Python code:

from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()

# Set up environment variables with fallback values
os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
os.environ["AGENTOPS_API_KEY"] = os.getenv("AGENTOPS_API_KEY")

Usage

Initialize AgentOps at the beginning of your application to automatically track all Gemini API calls.

import agentops
from google import genai

# Initialize AgentOps
agentops.init()

# Create a client
client = genai.Client(api_key="YOUR_GEMINI_API_KEY")

# Generate streaming content
for chunk in client.models.generate_content_stream(
    model='gemini-2.0-flash-001',
    contents='Explain quantum computing in simple terms.',
):
    print(chunk.text, end="", flush=True)

Examples

For more information on using the Google Gen AI SDK, refer to the official documentation.