Gemini AI Wrapper
The Astralog Gemini wrapper transparently monitors all your interactions with the Gemini API. It captures token usage, prompts, completions, and latency.
Installation
pip install astralog-gemini astralog google-generativeai
Setup
# agent.py
import google.generativeai as genai
from astralog import Client
from astralog_gemini import track_gemini
astralog_client = Client(api_key="ast_sk_live_xxxxxxxxxxxxx")
genai.configure(api_key="AIza...")
model = genai.GenerativeModel('gemini-1.5-flash')
# Seamlessly wrap the Gemini model
tracked_model = track_gemini(model, astralog_client, model_name="gemini-1.5-flash")
# Use it normally. The wrapper will automatically extract:
# - Total tokens consumed
# - Model used
# - Call latency
# - Full prompts and responses
response = tracked_model.generate_content("Hello!")
Cost Control & Visibility
By wrapping your LLM clients, Astralog generates specific ai_inference events in ClickHouse. You can use our Query Interface to instantly calculate your total token usage costs by model and detect prompt injections or hallucination anomalies.