|
| 1 | +# Gemini Integration |
| 2 | + |
| 3 | +With just a few changes in your ```Gemini``` client setup, you can start using the Invariant Gateway to visualize and debug your traces. |
| 4 | + |
| 5 | + |
| 6 | +## Getting the Invariant API Key |
| 7 | + |
| 8 | +Visit the [Explorer Documentation](https://explorer.invariantlabs.ai/docs/explorer) to learn how to obtain your own API key. |
| 9 | + |
| 10 | +## Setup Gemini API Key |
| 11 | + |
| 12 | +```bash |
| 13 | +export GEMINI_API_KEY={your-gemini-api-key} |
| 14 | +``` |
| 15 | + |
| 16 | +## Code |
| 17 | + |
| 18 | +```python |
| 19 | +import os |
| 20 | + |
| 21 | +from google import genai |
| 22 | + |
| 23 | +client = genai.Client( |
| 24 | + api_key=os.environ["GEMINI_API_KEY"], |
| 25 | + http_options={ |
| 26 | + "base_url": "https://explorer.invariantlabs.ai/api/v1/gateway/{add-your-dataset-name-here}/gemini", |
| 27 | + "headers": { |
| 28 | + "Invariant-Authorization": "Bearer your-invariant-api-key" |
| 29 | + }, |
| 30 | + }, |
| 31 | +) |
| 32 | + |
| 33 | +result = client.models.generate_content( |
| 34 | + model="gemini-2.0-flash", |
| 35 | + contents="Explain how SSL works", |
| 36 | + config={ |
| 37 | + "maxOutputTokens": 200 |
| 38 | + }, |
| 39 | +) |
| 40 | + |
| 41 | +print("result: ", result) |
| 42 | +``` |
| 43 | + |
| 44 | +This would push your trace to the [Invariant Explorer](https://explorer.invariantlabs.ai/) where it will be available under the dataset used above. |
| 45 | + |
| 46 | +## Explore other integrations |
| 47 | + |
| 48 | +<div class='tiles'> |
| 49 | + |
| 50 | +<a href="../openai" class='tile'> |
| 51 | + <span class='tile-title'>OpenAI Integration →</span> |
| 52 | + <span class='tile-description'>Seamlessly connect to OpenAI APIs through the Invariant Gateway.</span> |
| 53 | +</a> |
| 54 | + |
| 55 | +<a href="../anthropic" class='tile'> |
| 56 | + <span class='tile-title'>Anthropic Integration →</span> |
| 57 | + <span class='tile-description'>Leverage the Invariant Gateway for smooth Anthropic API interactions.</span> |
| 58 | +</a> |
| 59 | + |
| 60 | +<a href="../../agent-integrations/openai-swarm" class='tile'> |
| 61 | + <span class='tile-title'>OpenAI Swarm Integration →</span> |
| 62 | + <span class='tile-description'>Enhance and debug your OpenAI Swarm agents effortlessly using the Gateway.</span> |
| 63 | +</a> |
| 64 | + |
| 65 | +</div> |
0 commit comments