Skip to main content
This integration method is maintained but no longer actively developed. For the best experience and latest features, use our new AI Gateway with unified API access to 100+ models.
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

4

Install the Google Generative AI SDK

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

Import and configure the client

If you’re using Vertex AI integration (with GOOGLE_GENAI_USE_VERTEXAI=True), you need to modify the target URL to point to the Vertex AI endpoint:
Make sure the GOOGLE_CLOUD_LOCATION environment variable is set to your Google Cloud region (e.g., us-central1).
6

Generate content using the model

Adding User-Specific Headers with Client Factory Method

Currently, the Gemini Python SDK doesn’t support setting headers at request time, unlike OpenAI and Anthropic SDKs (see GitHub issue #698). As a workaround, you can create a factory function that dynamically generates client instances with specific headers.

Client Factory Method for User-Specific Headers

This factory method approach allows you to create clients with different user identifiers, session tracking, and custom properties for each request, working around the current limitation in the Gemini SDK while providing comprehensive tracking capabilities in Helicone.