Skip to content

AI Gateway: Use Google AI SDK for chat with Vertex AI #3795

@tomek-labuk

Description

@tomek-labuk

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions