Skip to content

AI Gateway: How to for using Vertex AI's Live API for real-time text streaming #3798

@tomek-labuk

Description

@tomek-labuk

How to for using Vertex AI's Live API for real-time text streaming through Kong AI Gateway. Send text messages and receive streaming responses.

Python script:

import asyncio
from google import genai

async def live_text_session():
    client = genai.Client(
        vertexai=True,
        project="your-project-id",
        location="us-central1",
        http_options={
            "api_version": "v1",
            "base_url": "http://localhost:8000/gemini"
        }
    )
    
    config = {"model": "gemini-2.0-flash-exp"}
    
    async with client.aio.live.connect(config=config) as session:
        await session.send("Tell me about quantum computing", end_of_turn=True)
        
        async for response in session.receive():
            if response.text:
                print(response.text, end="", flush=True)
        print()

asyncio.run(live_text_session())

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions