Skip to content

Firebase and Google Cloud billingUnexpected Gemini API charges on a Firebase project

Your Google Cloud bill shows Gemini API charges you didn’t expect, sometimes within a day. The usual cause is an API key that can call the Gemini API and is either public in your app or has no API restriction, so anyone who finds it can spend on your project. Here’s how to stop it today and make it harder to happen again, or hand it over at a fixed price.

Short answer

Stop the spend first: in the Google Cloud console, check the API metrics to see which key made the calls, then rotate it and restrict or delete every API key that allows the Generative Language API and isn’t a server-side Gemini key. If you can’t find the key fast, you can disable billing on the project, after checking what that takes down. Then move Gemini calls behind your server, turn on App Check for the Firebase services your app uses, set spend cap budgets where Firebase supports them, and keep an alert budget on the whole project. Budget alerts only warn you; they don’t stop charges.

Why it happens, and the fix

  1. 01

    A public Firebase key is allowed to call Gemini

    “never include the Gemini Developer API in the allowlist for a publicly accessible API key” Firebase, Learn about using and managing API keys for Firebase

    Firebase API keys ship inside your web or mobile app, so anyone can read them. That’s fine for Firebase services, which rely on Security Rules and App Check, but not for the Gemini API. Open APIs & Services > Credentials, check each key’s API restrictions, and remove the Generative Language API from any key your app ships with.

  2. 02

    The Gemini key is in your code or config

    “use a separate API key and restrict it to the applicable API” Firebase, Learn about using and managing API keys for Firebase

    A Gemini key in client code, a config file or a public repo can be copied and used from anywhere. Delete it in the Google Cloud console, create a new one restricted to the Generative Language API, and call Gemini only from your server or a Cloud Function, never from client code or config.

  3. 03

    The budget only sent an email

    “Budget alerts do not pause services.” Firebase, Avoid surprise bills

    An alerts-only budget emails you when spending crosses a threshold but keeps services running, so a night of abuse can finish before anyone reads it. Spend cap budgets pause a service for the rest of the month, but only a few Firebase services support them. Set caps where you can, and keep an alert budget with low thresholds on the project.

  4. 04

    The service you use has no spend cap

    “Spend caps budgets are only available for the following Firebase services: Firebase AI Logic, Firebase App Hosting, Cloud Functions for Firebase, and Firebase Extensions.” Firebase, Avoid surprise bills

    If your Gemini calls run through a raw API key rather than Firebase AI Logic or Cloud Functions, no Firebase spend cap covers them. Running the calls through one of the capped services, such as Firebase AI Logic or Cloud Functions, lets you set a spend cap budget that pauses that service at 100% for the rest of the month.

Checked against the vendor’s docs on : Firebase: API keys for Firebase; Firebase: Avoid surprise bills; Google Cloud: Best practices for managing API keys.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: How to cut your Firebase bill · Firebase App Check blocking requests · Firebase insecure rules alert

Questions

More on this error

Will Google refund the charges?

That’s Google’s decision and nothing is guaranteed. Open a billing support case right away with the project ID, the time window and what you changed to stop it, and keep the charges stopped while it’s reviewed.

Is the Firebase API key in my app a secret?

No. It identifies your project to Firebase, and your data is protected by Security Rules and App Check. The risk is when that same key is also allowed to call paid APIs such as Gemini.

Can you fix it for me?

Yes. The Firebase Cost-Cut Audit shows where the bill went and sets up key restrictions, spend caps and alerts. If you only need the leak closed, the App Fix Ticket covers that one fix, with a written diagnosis first. Neither can change what Google bills or refunds.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; we reply by email, usually within one business day.