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())
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
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!
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.