1

Create an account + Generate an API Key

Log into Helicone or create an account. Once you have an account, you can generate an API key.

2

Create Google Generative AI API Key

Visit the Google Generative AI API Key page. Follow the instructions to create a new API key. Make sure to save the key as you will need it for the next steps.

3

Set API keys as environment variables

export HELICONE_API_KEY=<your Helicone API key>
export GOOGLE_GENERATIVE_API_KEY=<your Google Generative AI API key>
4

Install the Google Generative AI SDK

Ensure you have the necessary packages installed in your Python environment:

pip install google-generativeai
5

Import and configure the client

import google.generativeai as genai
import os

genai.configure(
    api_key=os.environ.get('GOOGLE_GENERATIVE_API_KEY'),
    client_options={
        'api_endpoint': 'gateway.helicone.ai',
    },
    default_metadata=[
        ('helicone-auth', f'Bearer {os.environ.get("HELICONE_API_KEY")}'),
        ('helicone-target-url', 'https://generativelanguage.googleapis.com')
    ],
    transport="rest"
)
6

Generate content using the model

model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content("The opposite of hot is")
print(response.result)