Vertex AI (Enterprise)
Vertex AI Python SDK Integration
Use Vertex AI’s Python SDK to integrate with Helicone to log your Vertex AI usage.
Proxy Integration
Python SDK
1
2
Set API keys as environment variables
export HELICONE_API_KEY=<your API key>
export PROJECT_ID=<your Google Cloud project ID>
export LOCATION=<your location>
3
Install required packages
Ensure you have the necessary packages installed in your Python environment:
pip install google-cloud-aiplatform
4
Import libraries
from vertexai.generative_models import GenerativeModel
import vertexai
import os
5
Initialize Vertex AI with Helicone
HELICONE_API_KEY = os.environ.get("HELICONE_API_KEY")
PROJECT_ID = os.environ.get("PROJECT_ID")
LOCATION = os.environ.get("LOCATION")
vertexai.init(
project=PROJECT_ID,
location=LOCATION,
api_endpoint="gateway.helicone.ai",
api_transport="rest", # Must be 'rest' or else it will not work
request_metadata=[
('helicone-target-url', f'https://{LOCATION}-aiplatform.googleapis.com'),
('helicone-auth', f'Bearer {HELICONE_API_KEY}')
]
)
6
Initialize the model and generate content
model = GenerativeModel("gemini-1.5-flash-001")
response = model.generate_content("Tell me a fun fact about space.")
print(response.text)