Integrations / Google Gemini
To trace Gemini with Tracify, point the OpenAI client at Google's OpenAI-compatible endpoint and wrap it with the Tracify SDK. If you use Google's own google-genai library, record each call as a step instead.
Your code
Google Gemini
Tracify
One run.
Setup
Gemini speaks the OpenAI chat format on a compatible endpoint, so the OpenAI library is all you need.
pip install tracify-sdk openaiCreate a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.
export TRACIFY_API_KEY="tracify_sk_live_..."Create the OpenAI client with your Gemini key and Google's compatible base URL, then wrap it. Calls to chat.completions are recorded automatically.
import os
import tracify
from openai import OpenAI
gemini = tracify.wrap_openai(OpenAI(
api_key=os.environ["GEMINI_API_KEY"],
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
))
reply = gemini.chat.completions.create(
model="gemini-2.5-flash",
messages=[{"role": "user", "content": "Hello"}],
)There is no automatic wrapper for google-genai yet, so record the call as a step and copy the token counts from the response. The model call is then still visible in the run, with its tokens and time.
import tracify
from google import genai
client = genai.Client()
def ask(prompt: str) -> str:
with tracify.span("gemini", type="llm", input=prompt) as step:
response = client.models.generate_content(
model="gemini-2.5-flash", contents=prompt
)
usage = response.usage_metadata
step.set(
model="gemini-2.5-flash",
input_tokens=usage.prompt_token_count,
output_tokens=usage.candidates_token_count,
)
step.set_output(response.text)
return response.textRun your code one time, then open the Tracing page of your project. Your Gemini call shows up as a run with its steps in order, plus the tokens, time and any error for each call.
Good to know
The wrapper reads the OpenAI call format, so calls are labeled as OpenAI-style in the trace. The model name you send is always the one shown, so you can still tell models apart.
Good to know
Option A is fully automatic. Option B is a few lines you write yourself, because the google-genai library is not wrapped by the SDK yet.
Good to know
Tracify records the tokens the provider returns. A dollar cost is shown when you give the wrapper your own rates with calculate_cost (Python) or calculateCost (TypeScript), so the number always matches your real price plan.
Full details in the documentation. All integrations are listed on the integrations page.
