How to for configuring the Google Generative AI SDK to route Vertex AI chat requests through Kong AI Gateway. Authenticate with gcloud auth application-default login before running.
from google import genai
client = genai.Client(
vertexai=True,
project="",
location="",
http_options={
"api_version": "v1",
"base_url": "http://localhost:8000/gemini"
}
)
response = client.models.generate_content(
model="gemini-2.0-flash-exp",
contents="Explain machine learning"
)
print(response.text)