I initially posted this as a comment but it probably warrants its own topic.
I have reproduced this multiple times now. Steps:
-
Build a simple conversational voice agent app.
-
Add a Gemini key in the Secrets panel.
-
Test in AI Studio (works).
-
Publish and test (doesn’t work - connection is never established or drops instantly).
Debugging with the AI itself suggests two issues:
-
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.
-
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.