Gemini Integration
With just a few changes in your Gemini
client setup, you can start using the Invariant Gateway to visualize and debug your traces.
Getting the Invariant API Key
Visit the Explorer Documentation to learn how to obtain your own API key.
Setup Gemini API Key
Code
import os
from google import genai
client = genai.Client(
api_key=os.environ["GEMINI_API_KEY"],
http_options={
"base_url": "https://explorer.invariantlabs.ai/api/v1/gateway/{add-your-dataset-name-here}/gemini",
"headers": {
"Invariant-Authorization": "Bearer your-invariant-api-key"
},
},
)
result = client.models.generate_content(
model="gemini-2.0-flash",
contents="Explain how SSL works",
config={
"maxOutputTokens": 200
},
)
print("result: ", result)
This would push your trace to the Invariant Explorer where it will be available under the dataset used above.