Published Conversational Agent Cannot Connect to TTS API

I initially posted this as a comment but it probably warrants its own topic.

I have reproduced this multiple times now. Steps:

  1. Build a simple conversational voice agent app.

  2. Add a Gemini key in the Secrets panel.

  3. Test in AI Studio (works).

  4. Publish and test (doesn’t work - connection is never established or drops instantly).

Debugging with the AI itself suggests two issues:

  1. A conflict between the Gemini SDK’s default WebSocket URL and the AI Studio proxy interceptor, which resulted in a double slash (//ws/) in the connection URL.

  2. AI Studio does server-side string substitution on the fly, while Cloud Run just serves the raw compiled JS bundle containing the literal string “MY_GEMINI_API_KEY”, where “MY_GEMINI_API_KEY” is the name of the secret holding your gemini key.

It is relatively easy to get a workaround for issue 1 but all efforts to get the agent in AI studio to fix issue 2 have failed, consuming a lot of tokens in the process. It alternates between fixing the published app (and breaking it in Studio) and vice versa.

Some help or guidance on this from the AI Studio team would be appreciated. I have had to cancel some demos because of the issue. I had never previously published a voice agent so I don’t know if the issue is due to the latest updates, but the net effect of this issue is that a voice agent cannot be published successfully. If anyone has been able to do so recently, please advise.

3 Likes

+1 here. I can reproduce this at will by creating a new voice agent and attempting to publish. 404 errors in the CloudRun log and websocket errors to the same URL in the browser console.

2 Likes

+1 here as well. Same errors I reported at Help! AI WS connection works in preview environment but doesn't work in deployed! - #2 by Louis15 and it’s a widespread issue. After a while Gemini returns with a timed out connection as well.

1 Like