Gemini live api won't connect from local computer

Hi, I am trying to connect to the live api using Vertex AI and when I am running my code on my local machine I get a timeout error during opening handshake. When I am running my code from Google Cloud shell then it works. I have tried from two different computers (both macOS and 2 different networks). Has anyone run into this issue before? What would be the solution or some steps to debug it?

Here is the code I am running:

from google import genai
from google.genai.types import (
    Content,
    LiveConnectConfig,
    Modality,
    Part,
)
import asyncio

client = genai.Client(
    vertexai=True,
    project=GCP_PROJECT,
    location="global"
)
MODEL_ID = "gemini-2.0-flash-live-preview-04-09"

async def main():

    async with client.aio.live.connect(
        model=MODEL_ID,
        config=LiveConnectConfig(response_modalities=[Modality.TEXT]),
    ) as session:
        text_input = "Hello? Gemini, are you there?"
        print("> ", text_input, "\n")
        await session.send_client_content(
            turns=Content(role="user", parts=[Part(text=text_input)])
        )

        response = []

        async for message in session.receive():
            if message.text:
                response.append(message.text)

        print("".join(response))
    # Example output:
    # >  Hello? Gemini, are you there?
    # Yes, I'm here. What would you like to talk about?

if __name__ == "__main__":
    asyncio.run(main())

Hi @manmat , welcome to the forum.

Have you already done the authentication step locally (e.g. with gcloud auth application-default login)? Also, could you please share the exact error message??

Thank you.

Hi @GUNAND_MAYANGLAMBAM , thanks for the reply. Someone actually figured out the issue on the google cloud forum, here is the link to that: Gemini Live API handshake times out from local machine but works in cloud shell - Generative AI & Foundational Models - Google Developer forums

I was using the wrong location. I don’t see why global works in the cloud shell but not locally though :sweat_smile:.