Gemini API Usage, Billing, and Spend Cap Monitoring

Monitor reported Gemini API costs and Cloud Billing spend caps with a least-privilege service account. Covers JSON keys, billing delays, and balance limits.

Costs only · Not a balance

Guide updated

Costs and caps are implemented but await live-account verification. Google App Optimize is in Preview; real project coverage and the minimum IAM policy have not been validated with a live account. This is not prepaid balance retrieval.

Required credentials
Google service account JSON
Monitoring currency
Official billing currency · e.g. USD, CNY, JPY
What is monitored
Reported costs / Cloud Billing monthly cap / reported cost difference · not balance
Official costs for the selected Google Cloud project from the start of the current US Pacific month to query time. Filtered by exact SKU membership in the Cloud Billing catalog for Gemini API service AEFD-7695-64FA. Before credits, in the report currency; no conversion, token-price estimate or Vertex AI costs.

How to check Gemini API usage, billing, and spend caps manually

  1. Open the AI Studio Billing page to see the billing account, prepaid credits, and cost breakdown.
  2. Open the Spend page and use Monthly spend cap to view or edit the project's monthly cap.
  3. For per-SKU detail, open Cloud Billing Reports in the Google Cloud console, group by SKU, and filter to the Gemini API service.
  4. Billing data processing takes about 10 minutes, and the cost graphs on the Billing and Spend pages can take up to 24 hours to update.
Open official Gemini / Google AI Studio page(opens in a new tab)

Connect Gemini / Google AI Studio to Quota Monitor

  1. 1. Confirm that cost monitoring meets your needs

    Sign in to Google AI Studio with the account responsible for Gemini API use. For precise prepaid funds, view official Billing; this integration cannot replace it. A project administrator should set up permissions, while a dedicated service account handles routine reads. Check: you accept delays exceeding 24 hours and will not treat the difference as wallet funds.

  2. 2. Find the Google Cloud project behind the model key

    In AI Studio → API Keys, identify the project that owns your business key. Select the same project in the Google Cloud console's top project selector. In project settings, copy Project ID (for example my-gemini-project), not its display name or numeric Project number. Do not copy the model key. Open Billing, confirm a linked billing account and note the billing currency. Check: project ID, business key ownership and currency all match.

  3. 3. Enable the required APIs

    Keep the target project selected. Open APIs & Services → Library; search for and enable App Optimize API, Cloud Billing API, Cloud Billing Budget API and Cloud Resource Manager API. Leave already-enabled APIs alone. App Optimize is Preview: if your organization blocks it, stop and contact an administrator instead of weakening policy. Check: Enabled APIs & services lists appoptimize.googleapis.com, cloudbilling.googleapis.com, billingbudgets.googleapis.com and cloudresourcemanager.googleapis.com.

  4. 4. Create the minimal project custom role

    As a project administrator, activate Cloud Shell using the console toolbar and confirm the target project. In the Cloud Shell editor, use File → New File to create quota-monitor-gemini-role.json, paste the complete JSON below and save it. In its terminal run: gcloud iam roles create QuotaMonitorGeminiCost --project=PROJECT_ID --file=quota-monitor-gemini-role.json. Replace PROJECT_ID with the ID from step 2; do not leave the placeholder.

    If that role exists, inspect it in IAM & Admin → Roles and reuse it only if its purpose and permissions match; do not overwrite another application's role. Cloud Shell is Google's environment, not the Quota Monitor terminal. Check: the target project contains QuotaMonitorGeminiCost with exactly these seven permissions. Creating a role does not grant it.

    Cost report role JSON (includes temporary report creation)

    {
      "title": "Quota Monitor Gemini Cost",
      "description": "Read project costs and budgets; create temporary cost reports.",
      "stage": "BETA",
      "includedPermissions": [
        "appoptimize.reports.create",
        "appoptimize.reports.getData",
        "appoptimize.operations.get",
        "billing.resourceCosts.get",
        "billing.resourcebudgets.read",
        "resourcemanager.projects.get",
        "serviceusage.services.use"
      ]
    }

    Copies the complete JSON without keys or account details.

  5. 5. Create a dedicated service account

    Open IAM & Admin → Service Accounts in the same project, click Create service account, and name it quota-monitor-gemini. Skip optional role and user-access grants for now; the next step binds the exact custom role. This is a program identity, not a personal Google login. Check: record its complete .iam.gserviceaccount.com email and confirm it has no inherited or additional broad Owner/Editor access.

  6. 6. Grant the custom role to that identity

    Open the target project's IAM → Grant access. In New principals, enter the service account email from step 5, then Select a role → search Quota Monitor Gemini Cost → Save. Do not grant it to your own login email or choose the Viewer/Editor/Owner templates. Check: that service account's IAM member row actually has the custom project role. A role definition without this binding cannot authorize a query.

  7. 7. Create and protect a JSON private key

    Return to Service Accounts → select the dedicated account → Keys → Add key → Create new key → JSON → Create. Open the downloaded file in a secure editor and confirm type is service_account, project_id matches the project, and private_key, private_key_id and client_email are present. A model key from API Keys is not a substitute.

    This file contains a long-lived private key. Keep it in a password manager or secure location; never commit it to Git or put it in chat or tickets. If organization policy disallows service account keys, this version has no alternative identity flow; do not disable that protection. Check: the complete JSON is securely saved and only required keys remain in Keys.

  8. 8. Optionally check an existing Cloud Billing spend cap

    Ask a billing/project administrator to open Billing → Budgets & alerts and inspect the Gemini budget. Only an actual Spend cap scoped to this one project and the Gemini API service, using Month and excluding all credits, matches. Email-only budget alerts are not hard caps; multi-project or other-service budgets are not applied.

    You do not need to create or change a production cap for this integration. Costs work without a matching cap. A limit created in AI Studio may not be this Cloud Billing cap. Check: you know which limit you are comparing, or accept costs alone. Quota Monitor does not create, change or lift upstream restrictions.

  9. 9. Add the connection inside your Quota Monitor project

    Open the target business project → add provider connection → Gemini / Google AI Studio (costs & limits). Name it and copy the entire JSON file into the masked Google service account JSON field, not chat. Leave Google Cloud project ID blank to use the JSON's project_id. For another project, first enable its APIs and bind the same service account to the role there, then enter its Project ID.

    Set Google billing currency to the three-letter uppercase code confirmed in step 2, such as USD, CNY or JPY; no currency conversion is performed. Click Save and connect to project. Check: the connection is in the correct project and the private key is not displayed again. For save failures, inspect format and permissions without sharing JSON.

  10. 10. Sync and distinguish costs, caps and the difference

    Wait for first sync or click Sync costs. The service obtains a short-lived access token, reads Gemini SKU membership, creates and reads a temporary cost report, then separately reads a matching spend cap. Incomplete cost pagination never saves a partial total. A cap failure keeps valid costs and marks the cap unavailable. Check: the card shows reported monthly costs, not a balance, plus the Pacific month and delay notice. Cloud Billing cap, reported cost difference and official enforcement state are separate.

  11. 11. Reconcile the same scope with Google

    In Cloud Billing Reports, select the same project, current month and Gemini API service, and compare pre-credit costs in the same currency. Do not compare the whole billing account, Vertex AI, net costs after credits or AI Studio prepaid funds. Inspect Cloud Billing Spend cap and AI Studio Limits separately. Check: time, service, project and cost basis match. Newly incurred costs need time to report; a positive difference is no guarantee that calls will work.

  12. 12. Rotate and revoke keys safely

    Create a replacement JSON in the dedicated account's Keys, rotate credentials in Quota Monitor connection management, verify a successful sync, then delete the old key in Google. When stopping, remove monitoring/delete the Quota Monitor connection and revoke that dedicated key and unused role binding in Google. Do not delete other applications' identities or roles. Check: the old key is invalid and only necessary access remains. Share only error codes and times when reporting issues, never a private key or access token.

What Quota Monitor reads from Gemini / Google AI Studio

  • App Optimize is in Preview. Costs usually arrive within a day and may lag over 24 hours. Refresh reads reported data, not live settlement; sync time is not the billing cutoff. Zero means no reported matching costs, not no spending or guaranteed capacity.
  • This connection does not retrieve prepaid Gemini funds, personal Gemini subscriptions, Vertex AI or the entire billing account. No per-key cost filtering: keys in one Google project share that project cost scope.
  • Only an actual Cloud Billing spendCap matching one project, the Gemini service, a monthly period and excluded credits is used. Alert-only budgets are not hard caps. AI Studio project caps and billing-account tier caps are outside this query.
  • The difference is a same-currency, same-scope cap minus reported costs, not live available capacity. Enforcement uses faster estimated costs and can block calls while a positive difference is shown here. Missing access, failed pages or a changing cap are shown as unavailable, not zero or unlimited.
  • Each sync creates one temporary report in the target project; Google expires it after 24 hours. This permission cannot change billing or top up funds. The Preview report API has no additional API charge during Preview, but Google's terms, quotas and other cloud charges still apply.
  • The guide and synthetic regression tests are not live verification. Validate a small, tightly permissioned project first. Never grant admin access, disable organization security controls or share private keys to troubleshoot.
  • The dashboard shows the latest successful cost snapshot. Refresh cannot remove upstream reporting delays. An old cost and timestamp after a failed query are not a new report.

Gemini / Google AI Studio FAQ and troubleshooting

Why does my model API key not work?
A Gemini model key authorizes model calls, not billing reports or IAM access. Complete steps 4–7 for a minimal service account and JSON key. User OAuth credentials, Cookies and external identity configurations are not supported.
What if I see 403, a disabled API or a role creation error?
Check the selected project, all four enabled APIs, the service account email and the custom-role IAM binding. The role must match the JSON; billing.resourcebudgets.read covers the single-project budget without granting billing-account administration. If Preview APIs or custom roles are restricted, ask your administrator about support rather than granting Owner/Editor.
Why are costs zero or unchanged after a successful refresh?
The current report has no matching reported Gemini costs. Check the project and whether traffic actually goes through Vertex AI, then allow for reporting delays that may exceed 24 hours. Refresh cannot accelerate Google settlement and does not prove any balance remains.
Why can I see costs but not the limit?
Check single-project budget-read permission, the Gemini/monthly/exclude-credits scope, and an actual Spend cap. Ordinary alert budgets, other services, multiple projects and AI Studio caps are not Cloud Billing caps here. Reconciling settings, duplicate matches, currency mismatch and API failures produce unavailable, never zero.
Why does the currency or amount differ from billing?
Configure the report's three-letter currency. Quota Monitor does not convert amounts or label yuan as dollars. Match Pacific month, project, Gemini service, pre-credit costs and reporting delay. Mixed-currency cost rows cause a query failure instead of being added together.
Why are calls blocked despite a positive difference?
Cap enforcement uses faster directional cost data. AI Studio caps, account restrictions and actual funds can also stop calls. This difference is cost information, not a promise of available model capacity; check the official reason on Google's platform.
Why does the Gemini API return 402 Payment Required?
Google documents this as a depleted Prepay credit balance. When the billing account reaches $0, every API key in every project linked to it stops at once until you add credits or turn on auto-reload; retries will not succeed. Prepay credits expire 12 months after purchase. When the billing account reaches its tier's monthly spend cap, all linked projects pause until the 1st of the next month. Quota Monitor reads reported costs and the Cloud Billing spend cap, not the Prepay credit balance.

Official Gemini / Google AI Studio references

Prepared by Quota Monitor, not an official provider tutorial. Interfaces and permissions may change; check official pages. Verification is limited to the scope stated here.

Monitor Gemini / Google AI Studio automatically

Checking a console by hand is easy to forget. Quota Monitor reads Gemini / Google AI Studio through its official API for you.

  • Refreshes every 10 minutes by default, and you can refresh manually at any time.
  • Internal budget warnings, invalid credentials and sync failures rise to the top; reported costs are not wallet funds.
  • Group cost reports by project and read the same scoped costs through remote MCP. Internal budgets never change provider limits.
Start for free

See current Gemini API prices