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