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

Set API keys as environment variables

export HELICONE_API_KEY=<your API key>
export GCLOUD_API_KEY=<your Google Cloud API key>
3

Install necessary packages

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

Send a request using fetch

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

const url = 'https://gateway.helicone.ai/v1/projects/your-project-id/locations/your-location/publishers/google/models/model-name:streamGenerateContent';

const headers = {
  'Authorization': `Bearer ${process.env.GCLOUD_API_KEY}`,
  'Content-Type': 'application/json',
  'Helicone-Auth': `Bearer ${process.env.HELICONE_API_KEY}`,
  'Helicone-Target-URL': `https://${LOCATION}-aiplatform.googleapis.com`,
  'User-Agent': 'node-fetch'
};

const body = JSON.stringify({
  contents: {
    role: 'user',
    parts: { text: 'Which theaters in Mountain View show Barbie movie?' }
  },
  generation_config: { maxOutputTokens: 1 }
});

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

VertexAI 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

Set API keys as environment variables

export HELICONE_API_KEY=<your API key>
export GCLOUD_API_KEY=<your Google Cloud API key>
3

Install necessary packages

Ensure you have the necessary packages installed in your Javascript project:
npm install @google-cloud/vertexai
4

Import VertexAI and configure the client

import { VertexAI } from "@google-cloud/vertexai";

const vertex_ai = new VertexAI({
  project: "your-project-id",
  location: "your-location",
  apiEndpoint: "gateway.helicone.ai",
});
5

Set up custom headers

const customHeaders = new Headers({
  "Helicone-Auth": `Bearer ${process.env.HELICONE_API_KEY}`,
  "Helicone-Target-URL": `https://${LOCATION}-aiplatform.googleapis.com`,
});
6

Define request options

const requestOptions = {
  customHeaders: customHeaders,
} as RequestOptions;
7

Get the generative model

const generativeModel = vertex_ai.preview.getGenerativeModel(
  {
    model: "model-name"
  },
  requestOptions // Pass request options
);
8

Generate content

const result = await generativeModel.generateContent({
  contents: [{ role: "user", parts: [{ text: "How are you doing today?" }] }],
});
console.log(result);