Skip to content

AI Gateway: Google AI SDK for gemini chat roure #3788

@tomek-labuk

Description

@tomek-labuk

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions