How to limit my budget cost say $30 a month spent for Gemini api?

I want to deploy my poc app. I like a project level settings that will stop gemini api usage once it hits say $30 and not code level like counting tokens or api call.

Any good documentation you can refer me to? I don’t see any about it on ai studio unlike openAI where I can set a budget for a project.

Welcome to the forums!

Google Cloud does not let you set a hard limit on expenses, although you can cap your API usage or write a program that does impose a hard limit.

It does provide a way for you to create a budget and set alerts on it.

Absolutely absurd, this. Is this still the case even now in March 2025? Literally in disbelief that it seemingly doesn’t exist. How would anyone use Gemini API in their apps etc without this basic protective feature that all rivals have?

There is now documentation on how to do this.

The steps are:

  1. Enable Cloud Billing API
  2. Create a Budget
  3. Create a Cloud Pub/Sub topic to receive notifications when the Budget is hit
  4. Connect the Budget to the Cloud Pub/Sub Topic
  5. Create a Cloud Run Function that is triggerred when a message is sent to the Pub/Sub Topic (that is, when the Budget is reached) that will disable billing on the project (code is provided in the docs)
  6. Configure IAM to give the Service Account associated with the Cloud Run Function to disable billing for the project
1 Like

Thank you. Okay…so…I had Claude set something like this up for me a few days ago, but realised 2-3 days later that it had been charging me around $1 a day! Is this method cost-free?

This is SO INSANE that this extremely basic feature is not implemented. Just make a check in the code and throw an error if you are above the limit. Every LLM provider has this.

Makes it very hard to choose Gemini as my LLM provider.

Ooof. Big miss, in my opinion. As a dabbler in AI, building AI-powered products by myself in my spare time, I really NEED to ensure I don’t go over budget. With Anthropic and OpenAI I manually top off my account as needed. But if I trigger a call and it ends up burning through $100 without me even knowing it, that would really hurt.

Yes I see that there is a way to set it up manually, but it’s pretty ridiculous that I’d have to do that and it’s probably enough to keep me away.