How to for configuring the Google Generative AI SDK to route Gemini chat requests through Kong AI Gateway. Set the custom base_url in http_options to point to your Kong route.
Python script:
from google import genai
client = genai.Client(
api_key="your-api-key",
http_options={
"api_version": "v1beta",
"base_url": "http://localhost:8000/gemini"
}
)
response = client.models.generate_content(
model="gemini-2.0-flash-exp",
contents="Hello! How are you?"
)
print(response.text)