Huge Gemini API bill
What happened?
I just got billed around $140 for Gemini API. I enabled billing because I was using imagen API, but I just got a huge bill where most of it was not imagen, but "Generate content cached input token count gemini 2.5 pro long input".
What did you expect to happen?
I though Gemini CLI was free with huge limits, I definitely didn't go crazy on it, just some code review. Even if I went over the free portion, it should have been clear that charging was possible. This is very frustrating.
Client information
$ gemini /about
# paste output here
Login information
Gemini API from ai studio
Anything else we need to know?
No response
yes sir same happened to me also
You need to contact google support for this.
but sir really love your open source work ; deeply inspired
Damn, ok so basically it was not Gemini CLI. Stupid cursor removed Gemini from the max models, but I thought it just got deselected by mistake. I selected it again, but now I am figuring out that the Gemini model on cursor is billed at API price automatically using my API.
It is definitely my mistake, but I also blame Cursor tbh. I am gonna remove all my API keys from env variables.
Since this situation was unrelated to gemini-cli you may want to close this issue.
Good to know. The cap on billing in Google Cloud may help you.
FYI it turns out gemini CLI was also working on my gemini API key, to prevent that change the auth for gemini. I will never put any API keys in my env variables again.
FYI, something very similar has just happened to me: https://github.com/google-gemini/gemini-cli/issues/2923, Gemini CLI stuck on rereading a file. Luckily a free tier. Added interim tips then:
- do use the API method, but one from an account or project that is not paid.
- monitor usage at https://console.cloud.google.com/apis/api/generativelanguage.googleapis.com/metrics or maybe https://console.cloud.google.com/apis/api/cloudaicompanion.googleapis.com one? * (the graphs are pretty pretty anyway, congrats to the GUI team in turn), select the right project (linked to the API that you are using here).
- set the warning or usage caps (
Quotas and system limits) also there too, if needed (but they may be delayed by a day or two, RTFM if so then) - oh, I see now that e.g. "the overall latency" (five minutes sometimes!) is also useful...
Update: * too lazy to read which URL it is, Grok AI (sic) claims the former:
The correct URL for monitoring Gemini CLI usage is https://console.cloud.google.com/apis/api/generativelanguage.googleapis.com/metrics. This is because Gemini CLI directly uses the Gemini API (generativelanguage.googleapis.com) for its operations, and the Google Cloud Console’s metrics for this API provide detailed insights into request counts, token usage, and errors, which are relevant for tracking CLI activity and preventing unexpected charges. The cloudaicompanion.googleapis.com endpoint is primarily for Gemini for Google Cloud features like Code Assist, not Gemini CLI.RecommendationsAccess Metrics: In the Google Cloud Console, go to APIs & Services > Metrics, select your project, and filter for generativelanguage.googleapis.com to view usage data. Ensure you have the Monitoring Viewer role (roles/monitoring.viewer) for access.
Set Quotas: To avoid billing surprises, set usage limits in the Google Cloud Console under Quotas for generativelanguage.googleapis.com.
Secure API Keys: Use a free-tier Google Cloud project or restrict API keys to generativelanguage.googleapis.com to limit usage and avoid charges from other tools accessing the key.
ver. 1.2
Being able to ask Gemini how is it going cost-wise seems like something one would want to do from an authenticated CLI account. Sure, I don't want Gemini.cli to modify cloud settings, but read only for some seems fine.
Also, that URL is loooog, and can we have a LAST_7_DAYS in addition to LAST_30_DAYS please.
FYI, Gemini AI (and any AI) is unsurprisingly a very bad source of info about that AI, as it gets scant info about how it works, usually or is even told not to reveal it. Also, Gemini AI has a very long (and sensible) system message not to mess with passwords credentials and such (see the code itself for details). First thing I do to most AIs is a set of FYI what they can do, via .md templates.
@Manamama - Not quite following .. there should or should not be a /billing related set of queries in your opinion?
I rephrase: the AI tools (Bing, Gemini, llama, whatever) come with a blank slate, after https://en.wikipedia.org/wiki/Reinforcement_learning_from_human_feedback, finetuning to the expected tasks, some basic system messages (often hidden) about tools and guardrails, etc. They thus have some basic info about tools (e.g. the MCP servers here) at hand but very little info about their backends, middlewares, and GUIs even. Billing (for their services) is very abstract to them. Yes, they may read something online when we query them, but it would be third- or fourth-party source then, and they are likely to hallucinate. As a quick fix, I distill any such HTMLs or PDFs to .md, if needed for a focused session. I hope that my end-user (using LLMs since 2022, if not earlier) tip helps.
It's still happening! See my issue report here: https://github.com/google-gemini/gemini-cli/issues/4495
When you think you are in the free tier for use and rates, and then Google hits you with a huge bill!!!
As a pure logical recursion exercise, I have just ased Google AI (online) about Google AI, Google, and ... your billing problem, this time, but with a link or two that Gemini AI had also self found. Here: https://github.com/google-gemini/gemini-cli/discussions/4472#discussioncomment-13818343 , IMHO also a sensible advice, apart from the Grok AI's one, thereinabove aka q.v. As fellow human, I do hope that both of these help, alongside my human advice, that old one hereabove and the new therein alike.
I had thought I was using oath authentication on my personal account but was actually using my token. I only realized when I got a bill for $145 after just one day of rather heavy gemini-cli use. I suspect a good chunk of the input tokens happened when it decided to some HUGE diffs after I stepped away while it was running and let the results print to the console rather than just piping them to wc.
---Session 1:
Agent powering down. Goodbye! │ │ │ │ Interaction Summary │ │ Tool Calls: 123 ( ✔ 121 ✖ 2 ) │ │ Success Rate: 98.4% │ │ User Agreement: 90.9% (11 reviewed) │ │ │ │ Performance │ │ Wall Time: 4h 5m 1s │ │ Agent Active: 1h 12m 51s │ │ » API Time: 28m 33s (39.2%) │ │ » Tool Time: 44m 17s (60.8%) │ │ │ │ │ │ Model Usage Reqs Input Tokens Output Tokens │ │ ─────────────────────────────────────────────────────────────── │ │ gemini-2.5-pro 144 36,674,810 56,431 │ │ │ │ Savings Highlight: 26,979,720 (73.6%) of input tokens were served from the cache, reducing │ │ costs.
--- Session 2:
Agent powering down. Goodbye! │
│ │
│ Interaction Summary │
│ Tool Calls: 153 ( ✔ 150 ✖ 3 ) │
│ Success Rate: 98.0% │
│ User Agreement: 88.2% (17 reviewed) │
│ │
│ Performance │
│ Wall Time: 5h 18m 36s │
│ Agent Active: 46m 8s │
│ » API Time: 29m 37s (64.2%) │
│ » Tool Time: 16m 31s (35.8%) │
│ │
│ │
│ Model Usage Reqs Input Tokens Output Tokens │
│ ─────────────────────────────────────────────────────────────── │
│ gemini-2.5-pro 162 48,948,598 81,005 │
│ │
│ Savings Highlight: 39,536,862 (80.8%) of input tokens were served from the cache, reducing │
│ costs. │
│ │
│ » Tip: For a full token breakdown, run /stats model. │
│
Do format such lines as code in future, @jms90h5 . Especially on mobile 📲 they are illegible.
Now, to read them and cogitate some, I had Grok AI scan (plus calculate) it this time to be able to decipher.
A fuller Grok's take in below, but my tip: have some AI ponder on the pricelist vs your IRL usage too, as mine has been done in one minute, with ✌🏽 on 📱 and do post a well formatted tip for our mutual benefit.
Ref:
@jms90h5 Based on your reported usage for gemini-2.5-pro:
- Session 1: 9,695,090 non-cached input tokens ($72.71 @ $7.50/M) + 56,431 output tokens ($0.14 @ $2.50/M) = $72.85
- Session 2: 9,411,736 non-cached input tokens ($70.59 @ $7.50/M) + 81,005 output tokens ($0.20 @ $2.50/M) = $70.79
- Total: $143.64
This aligns with your $145 bill, assuming cached tokens are free. Check your Google Cloud billing dashboard or contact support for exact pricing. Consider setting usage caps to avoid surprises.