The GEMINI_API_KEY secret configured in my Firebase backend is not being passed into the server environment where my application code is running, causing all AI-related functions to fail because they have no credentials.

Hello, I’m facing a persistent environment variable issue in a Next.js application deployed on Firebase App Hosting. My Server Actions, which use Genkit to call the Gemini API, are failing because the GEMINI_API_KEY is not available in the execution environment. I’ve added diagnostic logging, and as you can see in the attached screenshot, process.env.GEMINI_API_KEY is undefined. What’s more revealing is that even standard App Hosting variables like GCLOUD_PROJECT are also undefined, which confirms the entire server environment is missing its configuration. I’ve verified that the secret is correctly defined in apphosting.yaml and have tried multiple fixes to the initializeFirebase() logic to force server-side initialization, but the environment variables are still not being populated. It seems like the connection between the App Hosting backend configuration and the running server code is broken. Any insights on what could be causing the environment to be empty would be greatly appreciated.

1 Like

This was happening to me yesterday too. I added the GEMINI_API_KEY in .env and deployed. It’s not getting picked up.