Kanji
・Cloud engineer / freelance ・Born in 1993 ・From Ehime / Living in Shibuya, Tokyo ・5 years AWS experience Profile details
Table of Contents
Whenever I expose a pay-as-you-go Cloud Run endpoint or let an autonomous agent call the Gemini API, one operational question always comes up: how do I cap unexpected spend before a bug or traffic spike drains the billing account? Traditionally, the only way to enforce a hard stop on Google Cloud was to wire a budget alert through Cloud Pub/Sub to a Cloud Run function that unlinks the billing account from the project. That pattern works, but it is a blunt instrument—unlinking billing shuts down every service in the project at once, including storage, networking, and management tooling, making recovery painful.
Google Cloud Billing now offers Spend Cap Budgets (GA) as a built-in circuit breaker. Instead of tearing down the entire project, a spend cap pauses new usage at the individual service level while leaving resources and data intact.
However, after inspecting Google Cloud SDK 594.0.0 locally alongside the live billingbudgets.googleapis.com v1 Discovery schema ( revision: 20261201 ), I found several strict validation rules that will break automation scripts if you assume Spend Caps behave like regular alert budgets. In this guide, I compare Spend Cap Budgets with Pub/Sub billing unlink and API quotas, then walk through the exact REST API payloads and constraints. Note that I have not yet triggered a 100% enforcement cutoff on a live billed project (not verified in production), so the enforcement timing and recovery window below are based on official documentation and live API schema checks.
594.0.0
billingbudgets.googleapis.com
revision: 20261201
429 RESOURCE_EXHAUSTED
As of December 2026, Spend Cap Budgets apply strictly to the following four API-based services. Persistent infrastructure such as Compute Engine VMs, GKE nodes, BigQuery storage, and Cloud Storage buckets are not paused by a spend cap.
AEFD-7695-64FA
generativelanguage.googleapis.com
C7E2-9256-1C43
aiplatform.googleapis.com
152E-C115-5142
run.googleapis.com
29E7-DA93-CA13
cloudfunctions.googleapis.com
One subtle detail is how Google evaluates the threshold. Spend caps use gross, estimated usage costs calculated from list prices—excluding Committed Use Discounts (CUDs), negotiated savings, and promotional credits—so the enforcement engine can trigger within minutes rather than waiting up to 24+ hours for finalized billing exports. In-flight requests already executing when the cap trips will finish and accrue charges, and minor overages due to telemetry lag are billed normally. Treating a spend cap as a fast circuit breaker and setting the target slightly below your true ceiling is the safest approach.
A spend cap budget tracks its operational status through three states: CONFIGURED , ENFORCED , and AWAITING_NEXT_PERIOD (displayed as Lifted in the console UI).
CONFIGURED
ENFORCED
AWAITING_NEXT_PERIOD
Lifted
Two operational behaviors are easy to overlook once a cap enters ENFORCED :
First, I checked whether the gcloud CLI installed on my local macOS workstation ( Google Cloud SDK 594.0.0 ) exposes any spend cap flags under gcloud billing budgets create .
gcloud
Google Cloud SDK 594.0.0
gcloud billing budgets create
gcloud --version | head -n 4 gcloud billing budgets create --help | grep -i 'spend-cap' || echo "no --spend-cap flag found"
Google Cloud SDK 594.0.0 alpha 2026.11.13 beta 2026.11.13 bq 2.1.42 no --spend-cap flag found
Neither GA nor beta subcommands currently expose a --spend-cap option. Inspecting existing alert-only budgets via gcloud billing budgets list also shows they carry no spendCap object and default to INCLUDE_ALL_CREDITS and FORECASTED_SPEND rules—both of which are rejected for spend caps.
beta
--spend-cap
gcloud billing budgets list
spendCap
INCLUDE_ALL_CREDITS
FORECASTED_SPEND
Next, I queried the live v1 Discovery document for billingbudgets.googleapis.com to confirm the exact SpendCap schema and enum values:
SpendCap
curl -sL 'https://billingbudgets.googleapis.com/$discovery/rest?version=v1' | python3 -c " import sys, json d = json.load(sys.stdin) sc = d['schemas']['GoogleCloudBillingBudgetsV1SpendCap'] print('Discovery revision:', d.get('revision')) print('inputState enum:', sc['properties']['inputState']['enum']) print('outputState enum:', sc['properties']['outputState']['enum']) "
Discovery revision: 20261201 inputState enum: ['STATE_UNSPECIFIED', 'CONFIGURED', 'ENFORCED', 'AWAITING_NEXT_PERIOD'] outputState enum: ['STATE_UNSPECIFIED', 'CONFIGURED', 'ENFORCED', 'AWAITING_NEXT_PERIOD']
From the 20261201 Discovery schema, five strict validation rules stand out when automating Spend Cap Budgets:
20261201
thresholdRules
CURRENT_SPEND
0.5
0.8
1.0
notificationsRule.enableProjectLevelRecipients
true
disableDefaultIamRecipients
false
pubsubTopic
monitoringNotificationChannels
budgetFilter.projects
budgetFilter.services
calendarPeriod
MONTH
creditTypesTreatment
EXCLUDE_ALL_CREDITS
ownershipScope
BILLING_ACCOUNT
ALL_USERS
amount
specifiedAmount
>= 0
lastPeriodAmount
spendCap.outputState
FAILED_PRECONDITION
PATCH
spendCap.inputState
Because gcloud lacks native flags, CI/CD pipelines and automation scripts must call billingbudgets.googleapis.com/v1 directly. Make sure billingbudgets.googleapis.com is enabled on your quota project and the caller holds billing.budgets.configureSpendCap on the billing account (or billing.resourcebudgets.configureSpendCap at the project level).
billingbudgets.googleapis.com/v1
billing.budgets.configureSpendCap
billing.resourcebudgets.configureSpendCap
The payload below ( spend-cap-cloudrun.json ) sets a $50/month cap on Cloud Run ( services/152E-C115-5142 ) for a single project. Replace the service ID with services/AEFD-7695-64FA to cap the Gemini API instead.
spend-cap-cloudrun.json
services/152E-C115-5142
services/AEFD-7695-64FA
{ "displayName": "cloud-run-monthly-spend-cap", "budgetFilter": { "projects": [ "projects/YOUR_PROJECT_ID" ], "services": [ "services/152E-C115-5142" ], "creditTypesTreatment": "EXCLUDE_ALL_CREDITS", "calendarPeriod": "MONTH" }, "amount": { "specifiedAmount": { "currencyCode": "USD", "units": "50" } }, "thresholdRules": [ { "thresholdPercent": 0.5, "spendBasis": "CURRENT_SPEND" }, { "thresholdPercent": 0.8, "spendBasis": "CURRENT_SPEND" }, { "thresholdPercent": 1.0, "spendBasis": "CURRENT_SPEND" } ], "notificationsRule": { "enableProjectLevelRecipients": true }, "spendCap": { "inputState": "CONFIGURED" } }
Include x-goog-user-project when invoking the endpoint with user credentials:
x-goog-user-project
BILLING_ACCOUNT_ID="01XXXX-XXXXXX-XXXXXX" QUOTA_PROJECT_ID="YOUR_ADMIN_PROJECT_ID" curl -sS -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: ${QUOTA_PROJECT_ID}" \ -H "Content-Type: application/json; charset=utf-8" \ -d @spend-cap-cloudrun.json \ "https://billingbudgets.googleapis.com/v1/billingAccounts/${BILLING_ACCOUNT_ID}/budgets"
When GET shows spendCap.outputState == "ENFORCED" , send a PATCH request with updateMask=spend_cap.input_state (the API requires spend_cap or spend_cap.input_state in update_mask whenever modifying an existing spend cap).
GET
spendCap.outputState == "ENFORCED"
updateMask=spend_cap.input_state
spend_cap
spend_cap.input_state
update_mask
{ "spendCap": { "inputState": "AWAITING_NEXT_PERIOD" } }
BUDGET_ID="YOUR_BUDGET_ID" curl -sS -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: ${QUOTA_PROJECT_ID}" \ -H "Content-Type: application/json; charset=utf-8" \ -d @lift-spend-cap.json \ "https://billingbudgets.googleapis.com/v1/billingAccounts/${BILLING_ACCOUNT_ID}/budgets/${BUDGET_ID}?updateMask=spend_cap.input_state"
For Terraform users, native spend_cap support in hashicorp/google ’s google_billing_budget resource has been tracked under provider issue #28575 , so availability depends on your exact provider release. Until your pinned provider version exposes it cleanly, managing the spend cap via the REST API script above while keeping google_billing_budget for alerts-only Pub/Sub notifications is the most predictable split.
hashicorp/google
google_billing_budget
#28575
Because Spend Cap Budgets only apply to direct (first-party) Google Cloud billing accounts—excluding reseller accounts—and disallow Pub/Sub topics on the same budget resource, a practical rollout splits responsibilities as follows:
disable_on_demand_billing
What I still want to observe in a real test project (currently not verified in production) is the exact latency between crossing 100% gross estimated spend and seeing Cloud Run or Gemini API return errors to clients, as well as how much shorter than the documented “up to 1 hour” recovery takes in practice. Checking the API schema constraints upfront makes it straightforward to deploy a low-dollar cap on a sandbox project first and verify the alerts before relying on it in production.
Real-time AI quant analysis of earnings reports, corporate filings, and momentum indicators for global equities and Japanese stocks.
Master conversation skills with realistic AI phone training and 5-axis feedback. Includes 16-lesson interactive academy and studio AI portraits.
Effortlessly snap receipts for instant AI itemization. Integrated with LINE for seamless group expense tracking and pain-free settlement.
Interactive AI personas (Fortune Teller, Butler, Bartender) host real-time games, challenges, and conversation starters for unforgettable gatherings.
Unbiased healthcare database featuring zero-additive filters and active ingredient cost performance metrics.