Google Gemini Wrapper

Wrap a Google GenerativeModel to automatically trace every generate_content() call.

Installation

pip install twosignal[google]

Usage

from twosignal import TwoSignal
from twosignal.wrappers.google import wrap_google
import google.generativeai as genai

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

model = wrap_google(genai.GenerativeModel("gemini-2.5-flash"))

response = model.generate_content("Hello")

What Gets Captured

FieldDescription
modelModel name (e.g., gemini-2.5-flash)
inputInput content or prompt
outputResponse text
usage.prompt_tokensInput token count
usage.completion_tokensOutput token count
costEstimated cost in USD

Async

response = await model.generate_content_async("Hello")

Both generate_content and generate_content_async are wrapped automatically.

Have questions? Join our community!

Connect with other developers and the 2Signal team.

Join Discord