403 Permission Error

I’m experiencing an issue with my Gemini API key when deploying an app built with Google AI Studio.

My application works perfectly inside the Google AI Studio preview environment. However, once I publish/deploy the app, the live version cannot access the Gemini API. The requests fail with a 403 Permission Error.

To troubleshoot, I have already tried the following:

  • Removed the existing API key and created a new one

  • Checked the API key restrictions carefully

  • Verified that the correct API key is being used in the deployed environment

Despite these steps, the deployed application still cannot reach the Gemini API, while the preview version inside AI Studio works without any problems.

Has anyone experienced a similar issue or knows what might cause this behavior?

Any guidance would be greatly appreciated.

1 Like

I am having the exact same issue. Still havn’t found the solution….

Mine too, it’s works perfectly on preview but on published cloud run, the api wont works

Guys, anyone solved this?

I’m experiencing the same. I restored the app to a very old version and still the same. Something happened and the env variables are not been recognized or used after publishing.

AI Studio publish now overwrites the Gemini API key. You need to replace them manually, for now I hope. From the publish screen in AIS, select Manage in Google Cloud. Select ‘Edit and Deploy new revision’. In both containers (nginx and app) select the Variables and Secrets. In the Environment Variables your GEMINI_API_KEY value will probably be empty. Add your API key into the value box. Repeat for the app container, adding the API key value if missing, unless the value is stored as a secret, in which case do not add the key in the environmental variables. Press Deploy. I used Claude to guide me through this.

It needs to be repeated every time you publish until they fix it.

Didn’t fix it. Actually the correct keys were already set there for me too. What’s weird is that an old app I made is still working.

For the app that this error occurs for I literally made 0 changes, the api key just randomly stopped working.

If anything the new feature where you set the secrets via an AIStudio settings dropdown isn’t working, since the keys are NOT being updated in the google cloud control panel.

There appears to be a new hell inflicted on us . Today it is demanding that an API key is needed, even though the key is set. Fails on preview and published version, which was for last night.