Skip to content
Billfuse

How to set a spending limit on the Gemini API

Last updated

Google gives the Gemini API three monthly spending limits: a spend cap you set on a project in Google AI Studio, the same kind of cap set as a budget in Google Cloud Billing, and a cap on your whole billing account that comes with your usage tier. If you prepay, your credit balance stops requests too. This page shows where to find and set them, what happens when one is reached, and what they don't cover.

Everything here was checked against Google's docs on November 12, 2026. The three reported messages and the note on API keys were added and checked on November 13, 2026. The sources are linked under the sections they back up.

The short version

  1. In Google AI Studio, open the Spend page.
  2. Under Monthly spend cap, click Edit spend cap.
  3. Enter an amount.

You need the project editor, owner or admin role. The cap can run about 10 minutes behind your spending.

Three limits, from Google and from you

AI Studio's spend caps aren't available on invoiced (offline) billing accounts, and Cloud spend cap budgets are only for first-party Google Cloud customers, not reseller accounts.

None of these is a limit on one API key. Google says API keys “have no independent billing settings”, and usage from every key in a project counts toward that project's spend cap. So a key that is the only key in its project is capped by that project's cap. If a key has already leaked, the steps for turning it off are in what to do when an AI API key leaks.

Sources: Google AI Studio, Billing, Google Cloud, Manage spend cap budgets

Set a project spend cap in AI Studio

  1. In Google AI Studio, open the Spend page.
  2. Under Monthly spend cap, click Edit spend cap.
  3. Enter an amount.

Source: Google AI Studio, Billing

Set a spend cap budget in Google Cloud

  1. In the Google Cloud console, go to Budgets & alerts and click Create new budget.
  2. Choose Spend cap enforcement, not Alerts only. Give the budget a name and click Next.
  3. Select one project, and the Gemini API as the service. The time range is always monthly. Click Next.
  4. Enter the Target amount, click Next, then click Finish.

Sources: Google Cloud, Manage spend cap budgets, Google Cloud, Budgets

Your tier's spend cap

When your billing account's total reaches the tier's cap, the Gemini API stops for every project linked to that billing account until the 1st of next month. So one runaway project can stop all your other projects on the same billing account.

Source: Google AI Studio, Billing

A 10-minute spend limit too

Google also limits how much you can spend in any 10 minutes: $10 on Tier 1, and $200 on Tiers 2 and 3. Google says whether these limits apply to you depends on your billing history and account standing. Go over one and requests fail with error 429 RESOURCE_EXHAUSTED. Google's advice is to wait and retry after a short period.

Source: Google AI Studio, Rate limits

What happens when you reach a limit

Your prepaid balance reaches $0

Requests fail with error 402 until you add credits. Every API key in every project linked to that billing account stops at the same time. Your projects don't drop back to the free tier; to get service back at your paid tier, you buy more credits. Google says not to retry a 402.

Error 402, as reported
{
  "error": {
    "code": 402,
    "message": "Your prepayment credits are depleted. Please go to AI Studio at https://ai.studio/projects to manage your project and billing. Learn more at https://ai.google.dev/gemini-api/docs/billing#prepay. ",
    "status": "RESOURCE_EXHAUSTED"
  }
}

This response is from a GitHub issue dated November 7, 2026. Google's docs describe the error (“Your Prepay credit balance is depleted.”) but don't show the response. A notice on Google's developer forum dated September 18, 2026 says these requests returned a 429 until then. Our guide to this error covers adding credits and what to check if your balance isn't $0.

A spend cap is reached

Google's docs don't say which error you get when a project cap, a Cloud spend cap or your tier's cap is reached. On Google's developer forum, developers have posted a 429 RESOURCE_EXHAUSTED with the message “Your project has exceeded its monthly spending cap.” or “Your billing account has exceeded its monthly spending cap”. In one of them, AI Studio showed spend below the cap.

Developers also report a banner in AI Studio: “You've reached the billing account tier cap and service has been paused.” (forum posts from October 22 and November 3, 2026). At the tier limit, Google's Billing page says service is paused for every project linked to the billing account until the 1st of next month. “Your tier's spend cap” above covers moving up a tier and asking for a higher cap.

If requests stop while you still have prepaid credits, Google says you may have hit your tier's limit, or the status of your Cloud Billing account may be the cause.

“You exceeded your current quota”

Error 429, as reported
{
  "error": {
    "code": 429,
    "message": "You exceeded your current quota, please check your plan and billing details.",
    "status": "RESOURCE_EXHAUSTED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Learn more about Gemini API quotas",
            "url": "https://ai.google.dev/gemini-api/docs/rate-limits"
          }
        ]
      }
    ]
  }
}

Google's advice for a 429 is to check that you're within the model's rate limits, then wait and retry. In one report the message goes on to name the quota, free-tier requests per day, and says to retry in 13 hours (GitHub, November 10, 2026). For a daily quota like that one, Google's errors page for the Interactions API says to wait until the quota resets or ask for an increase. The check below retries this 429 up to its attempt limit, daily quota or not.

This response is from Google's developer forum, November 5, 2026. Google's docs don't contain the sentence. The spend cap messages above say “monthly spending cap” instead.

Sources: Google AI Studio, Billing, Google AI Studio, API errors, API errors (Interactions API), Google AI Developers Forum, April 21, 2026, August 24, 2026

Stop your code from retrying a cap

Google says to retry only transient errors, like 429, 408 or 5xx, with a maximum number of attempts, and not to retry errors like 400, 402 or 403. The 10-minute spend limit comes back as a 429, and the cap errors developers have posted are 429s too. A loop that retries every 429 with no limit can keep failing until the cap changes. Check before you retry:

Python
from google.genai import errors

# For errors from client.models.generate_content
# Google: retry these, up to a maximum number of attempts
RETRY = {408, 429, 500, 502, 503, 504}
MAX_ATTEMPTS = 5


def spend_cap_reached(error: Exception) -> bool:
    """Best effort: a 429 whose message mentions a spending cap."""
    return (
        isinstance(error, errors.APIError)
        and error.code == 429
        and "spending cap" in (error.message or "").lower()
    )


def should_retry(error: Exception, attempts: int) -> bool:
    """attempts: how many times this request has been sent so far."""
    if not isinstance(error, errors.APIError) or attempts >= MAX_ATTEMPTS:
        return False
    if spend_cap_reached(error):
        return False
    # Everything else, such as 400, 402 (prepaid credits used up) and 403
    return error.code in RETRY
TypeScript
import { ApiError } from "@google/genai";

// For errors from ai.models.generateContent
// Google: retry these, up to a maximum number of attempts
const RETRY = new Set([408, 429, 500, 502, 503, 504]);
const MAX_ATTEMPTS = 5;

// The SDK puts Google's whole error response, as JSON, in error.message
function googleMessage(error: ApiError): string {
  try {
    return String(JSON.parse(error.message)?.error?.message ?? "");
  } catch {
    return error.message;
  }
}

// Best effort: a 429 whose message mentions a spending cap.
function spendCapReached(error: unknown): boolean {
  return (
    error instanceof ApiError &&
    error.status === 429 &&
    googleMessage(error).toLowerCase().includes("spending cap")
  );
}

// attempts: how many times this request has been sent so far.
function shouldRetry(error: unknown, attempts: number): boolean {
  if (!(error instanceof ApiError) || attempts >= MAX_ATTEMPTS) return false;
  if (spendCapReached(error)) return false;
  // Everything else, such as 400, 402 (prepaid credits used up) and 403
  return RETRY.has(error.status);
}

Call the retry check after each failed attempt. When it says yes, back off and try again. When the spend cap check says yes, stop and tell someone: the request will keep failing until the cap changes or the month resets.

We ran the checks with the Python SDK (google-genai 3.2.0 and 1.20.0) and the TypeScript SDK (@google/genai 3.2.0 and 1.10.0), against a local test server that sends the errors described above.

Sources: Google AI Studio, Troubleshooting, Google AI Studio, Rate limits, Google AI Studio, API errors, python-genai, js-genai

What the caps don't cover

Where Billfuse fits

Billfuse is the tool we built for these gaps. It doesn't replace Google's caps. Keep them on.

More guides

It's free while Billfuse is in early access. You can try it with sample data first, no sign-up needed.