Gemini Live API handshake times out from local machine but works in cloud shell

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). I have also tried different live api models. 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())

Hello @Matyas_Manninger,

Replace location="global" to location="us-central1".

Model gemini-2.0-flash-live-preview-04-09 is only available in us-central1, you can see this in its dedicated Model Card.

Note that Google said that preview models have some restrictions :

Points to a preview model which may not be suitable for production use, come with more restrictive rate limits, but may have billing enabled.

To specify a preview version, use the following pattern: <model>-<generation>-<variation>-<version>. For example, gemini-2.5-pro-preview-06-05.

Preview models are not stable and availability of model endpoints is subject to change.

You might be interested in taking a look at all the Google Models to learn more about them.

1 Like

Hi @LeoK,

Thanks for the answer. Changing to us-central1 seems to have solved the issue. Would you have any insights into why global works in the cloud shell though and not on local machines?

Thanks for the note about the preview model but this seems to be the only public model that supports text responses. 2.5 is in private GA and 2.5 with native audio only supports audio output as far as I am aware. The 2.0 is indeed not great for production, tool calling only seems to work every 1 out of 10 tries for example.

Also, the model card can’t be trusted as it’s not showing text output modality on this 2.0 flash live api model but it still works :smiley:

1 Like

@Matyas_Manninger,

Your Cloud Shell might be located in us-central1 which causes global to resolve to us-central1.

Also, thanks for your feedback on the docs, I tend to praise them blindly. Things move so fast in AI, I guess Google doesn’t always have time to update every page! :face_with_hand_over_mouth:

Definitely Google docs are superior to competitors in my opinion too, I like to praise them too. AI is just moving too fast probably for them to keep them always up to date probably.