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.

Proxy Integration

Fetch

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_API_KEY=<your Google Generative AI API key>
4

Install necessary packages

Ensure you have the necessary packages installed in your Javascript project:
npm install node-fetch
5

Send a request using fetch

const fetch = require('node-fetch');

const url = `https://gateway.helicone.ai/v1beta/models/model-name:generateContent?key=${process.env.GOOGLE_API_KEY}`;

const headers = {
  'Content-Type': 'application/json',
  'Helicone-Auth': `Bearer ${process.env.HELICONE_API_KEY}`,
  'Helicone-Target-URL': `https://generativelanguage.googleapis.com`,
};

const body = JSON.stringify({
  contents: [{
    parts: [{
      text: 'Write a story about a magic backpack.'
    }]
  }]
});

fetch(url, { method: 'POST', headers: headers, body: body })
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Google Generative AI SDK

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_API_KEY=<your Google Generative AI API key>
4

Install necessary packages

Ensure you have the necessary packages installed in your Javascript project:
npm install @google/genai
5

Import and configure the client

import { GoogleGenAI } from "@google/genai";

if (!process.env.GOOGLE_API_KEY) {
  throw new Error("GOOGLE_API_KEY environment variable must be set");
}

if (!process.env.HELICONE_API_KEY) {
  throw new Error("HELICONE_API_KEY environment variable must be set");
}

const genAI = new GoogleGenAI({
  apiKey: `${process.env.GOOGLE_API_KEY}`,
  httpOptions: {
    baseUrl: "https://gateway.helicone.ai",
    headers: {
      "Helicone-Auth": `Bearer ${process.env.HELICONE_API_KEY}`,
      "Helicone-Target-URL": "https://generativelanguage.googleapis.com", // Change this to "https://aiplatform.googleapis.com" if vertexai is set to true
    },
  },
});

6

Generate content using the model

async function generateContent() {
  const response = await genAI.models.generateContent({
    model: "gemini-2.0-flash-001",
    contents: "Why is the sky blue?",
  });
  console.log(response.text);
}

generateContent();