
Capping Vertex AI test costs: a 2,500 KRW stop line missed a 2,956 KRW bill, so we changed the defaults
Wherever an AI agent can spend cloud money, a missing setting should mean no spending. These are the defaults we set after a 2,500 KRW stop line missed a 2,956 KRW bill.
Our model evaluation runner had a code cap that stopped it at 2,500 KRW (about $1.80 at 1,400 KRW per dollar). On October 11, 2026, the budget alert showed 2,956 KRW actually billed. Almost all of it went on the Vertex AI model evaluation an AI coding agent ran on October 8 and 9 (about 330 call attempts in the main run, plus follow-up runs) while choosing a model for AXFamily, a family schedule app that hadn't launched yet. The runner's ledger counted the responses it received, and it badly underestimated the output of 62 attempts that ended with no response, 61 of them on 3.8 Flash. After that, we went through each path where the agent could spend money and changed what happens when a value is missing.
Sources: the AXFamily app repository's release plan (written Oct 9, corrected Oct 11), model evaluation notes, cost status doc, decision record and git history. Billed amounts come from the budget alert; token counts from Cloud Monitoring at 1,400 KRW per dollar. Rechecked 2026-11-10 (Korea time).
Contents (9)
- A 2,500 KRW stop line in code, 2,956 KRW on the bill
- The plan's 1,700 KRW estimate came from the ledger
- A quota lowered to 1,000 let all 4 requests through
- A default for each path that spends money
- budget-guard logged four 429s after its redeploy
- The circuit breaker defaults the other way
- Seven defaults that spend nothing when a value is missing
- Still open: the 10,000 KRW custom budget is pending
- FAQ
A 2,500 KRW stop line in code, 2,956 KRW on the bill
For each call, the runner added the cost from the response's usageMetadata to a ledger and refused to make the next call once the total passed 2,500 KRW. Attempts that ended without a response were counted at an estimated 1,500 output tokens each. When the evaluation finished, the ledger held 918.1 KRW from responses plus 666 KRW for 62 such attempts (61 of them on 3.8 Flash), 1,584.2 KRW in total. It never reached the stop line.
On October 11 the agent read the budget alert during an operations audit: 2,956 KRW for October. Pricing Cloud Monitoring's token counts for October 6 to 11 gives about 3,490 KRW, and about 72% of that, roughly 2,520 KRW, is 3.8 Flash output. The ledger had 595.6 KRW for 3.8 Flash, and that figure already included thinking tokens. So no further 3.8 Flash tests were run.
The three numbers cover slightly different ground. The 1,584.2 KRW ledger covers the main evaluation only; the 2,956 KRW bill and the token counts also include follow-up runs on October 9 (229.7 KRW by the ledger plus about 2.7 KRW for the quota test, about 232 KRW in all). We haven't confirmed why the token-count estimate of about 3,490 KRW is higher than the 2,956 KRW billed. The cost status doc only notes that billing may not have caught up yet and that the real total could rise to around 3,500 KRW.

In one run, 17% of 3.8 Flash attempts (10 of 59) went past the 60-second timeout, and a request the client abandons returns no response and so no usage. The agent had even written in the evaluation notes that it could not confirm from public docs whether the server keeps processing and billing a request the client dropped at 60 seconds. The cap still priced each of those attempts at only 1,500 output tokens.

The app's Cloud Function had a hole of the same kind. It counted output tokens from candidatesTokenCount alone, but 3.8 Flash produced thinking tokens even with thinkingBudget set to 0: 50 to 166 per call on average, up to 526. Thinking tokens are billed at the output rate. A commit on Oct 11 at 14:17 made output tokens the sum of response and thinking tokens. If the response token count is missing, the new code doesn't build a number from thinking tokens alone; it returns null, and that call is charged against the full unit cap. That rule was already in place, because returning 0 would leave the token budget open. The evaluation notes gained a line saying the ledger is a lower bound and is never used to judge cost, and the remaining ten or fewer real calls were limited to 3.5 Flash-Lite at 2 to 3 KRW each.
The plan's 1,700 KRW estimate came from the ledger
The agent wrote the internal-test release plan at 18:35 on October 9. Its second conclusion read: keep costs near zero with hard caps in code; budget alerts arrive hours late, so treat them as a backup. Its fifth conclusion put expected test spend at about 1,700 KRW, worst case 8,000 KRW plus whatever the alert delay lets through, and the cost table's first row put the evaluation already spent at the ledger value, 504 KRW, in a column labelled "confirmed". The total came to about 1,726 KRW.
By billing, 2,956 KRW had been spent before the plan was written; the running total had been flat since the morning of October 9. Had the test-period budget been created at 8,000 KRW as planned, the 50% line at 4,000 KRW would switch off AI, photo upload, notifications and media viewing, with only 1,044 KRW of room left.
On October 9 the operator lowered the monthly budget from 20,000 to 10,000 KRW, with two lines: switch features off at 50%, unlink billing at 100%. The agent applied the operator's October 11 instruction (features off at 5,000 KRW, billing unlinked at 10,000 KRW) to the test period's total in the plan as well. The status doc written that day explains why a monthly budget can't do it alone: it restarts from zero on November 1, so it can't cap a test that runs into November. The agent changed the planned custom-period budget to 10,000 KRW (October 8 to December 31, credits excluded) and added a correction under the plan's cost table.
A quota lowered to 1,000 let all 4 requests through
On October 8 the per-model input token quotas for Vertex AI were lowered to 2,000,000 a day and 200,000 a minute, which put the worst day at roughly 3,000 to 4,000 KRW per model. On October 9 we tested whether the quota actually bites. With 3.5 Flash-Lite's per-minute input token quota set to 1,000, the granted value showed 1,000 within two seconds. Two requests with 1,581 input tokens went out, then two more two minutes later. All four returned 200, with no 429. The quota went straight back to 200,000; the test cost about 2.7 KRW.
We couldn't tell whether enforcement was delayed or whether this quota doesn't apply to calls on the global endpoint. Since then the quota doesn't count as a cost block, and the app function's daily limit is the first line.
A default for each path that spends money
The evaluation runner, the deploy script, the production switches and CI are all paths the agent runs. For each one we decided what happens when a value is missing or wrong.
| Path | When the value is missing or wrong | Source |
|---|---|---|
| Production deploy script | Dry-run (read only). A real deploy needs --execute; --force is an error | Deploy script (Oct 10) |
| Deploy preflight | Any failed check stops the deploy. Model and location are confirmed with one free countTokens call | Deploy script (Oct 10) |
| Daily AI service cap | 0 (no AI). Test values: 10 units and 15 Vertex calls a day | Plan, function config |
| Production switches | Preflight fails if the AI or photo switches are on at deploy time | Deploy script (Oct 10) |
| Model usage | No token count means the full unit cap. Output = response + thinking tokens | Usage fix (Oct 11) |
| Test-period budget | Preflight error if the custom-period budget doesn't exist | Usage fix (Oct 11) |
| CI | Only the demo emulator project. Deploy or login commands, or cloud credentials, fail the build | CI config |
Run with no arguments, the deploy script (Oct 10, 15:20) collects facts, runs the preflight, prints the deploy commands and stops with "DRY-RUN: checks passed. Use --execute to deploy." (translated from Korean). The commit added 987 lines across 11 files, and its message lists 44 fixture tests for the checks. The preflight includes a countTokens call that sends the single word "ping" and isn't billed. A check of that kind the same day found that both models returned 404 in the locations this commit allowed (Seoul and Tokyo), and the operator picked global. What that did to the privacy policy is in our note on the AI processing location in the privacy policy.
Commands that change production settings were blocked by the agent's auto mode, so the operator ran them, and the result is checked with another dry-run preflight. Which clicks a person makes is covered in the AI agent permission table note.
budget-guard logged four 429s after its redeploy
This project's budget alerts also go to Pub/Sub, where a budget-guard function switches off four features (AI, upload, notifications, media) at 50% of the budget and unlinks billing from the project at 100%. We still don't make it the first line. Alerts can arrive hours late, and the function itself can lag: after its October 10 redeploy it logged four "no available instance" 429s alongside 122 successful runs. Alerts are redelivered, so the block isn't lost.
The circuit breaker defaults the other way
Zero-when-missing and dry-run-by-default fit only the side that spends money. The budget-guard function runs in test mode only when the DRY_RUN environment variable is exactly true; with it unset, it really switches features off and unlinks billing. A breaker that defaulted to test mode would block nothing the day someone forgot a setting.
None of this reaches services outside the Google Cloud budget. Photo storage on Cloudflare R2 and Workers is designed to be held by free-plan limits and a daily automatic pause (the Worker isn't deployed yet), watched by a $0.5 billing alert. Billing data shows up the next day, so while an evaluation runs the ledger is the only number you have. Keep its stop line well below the budget and estimate cut-off attempts generously. Once real users arrive, a test-period budget isn't enough and you need a per-day call cap; we did that for our spelling app in the note on LLM explanation costs and limits.
Seven defaults that spend nothing when a value is missing
- Make any script that calls a paid command dry-run when run with no arguments, and act only on an explicit flag such as
--execute. Don't accept--force. - Stop on any failed preflight check. Confirm model and location with a call that isn't billed, such as countTokens.
- Set the server's daily AI cap to 0 in code, and close it when the config document is missing the value or holds a string. Refuse to deploy while the AI switch is on.
- Count output as response plus thinking tokens, and count a call with no token count as the full unit cap, never 0.
- Let the evaluation runner judge its stop line from the ledger, then compare against billing the next day and treat the ledger as a lower bound.
- Set two budgets, monthly and a custom test period, and wire 50% to switching features off and 100% to unlinking billing. Make the deploy preflight fail if the custom-period budget is missing.
- Keep CI on emulator projects only, and fail the build when deploy or login commands show up in the repository's scripts or workflows.
Still open: the 10,000 KRW custom budget is pending
The repository's cost status doc (updated October 11) still lists the 10,000 KRW custom-period budget as pending. The deploy preflight errors without it, so it has to exist before any production deploy. The 100% path that unlinks billing has been checked only by 13 unit tests and a permissions review; we haven't actually cut billing. Whether the cut-off 3.8 Flash requests were billed is still unconfirmed at the SKU level, because billing export isn't turned on.
FAQ
Does a Firebase budget alert stop Vertex AI charges at the limit?
An alert alone doesn't stop billing. We have a function that switches features off at 50% and unlinks billing at 100%, but because alerts arrive late, the app function's daily limit comes first.
Does lowering a Vertex AI quota cap spending?
Not in our test. Right after we cut the per-minute input token quota to 1,000, four requests of 1,581 tokens all succeeded.
Is the Vertex AI countTokens call billed?
No; it isn't a generation call. Our pre-deploy check sends the single word "ping" just to see whether the model answers in that location.
Does thinkingBudget 0 mean no thinking-token cost?
Not with 3.8 Flash. With 0 it still produced 50 to 166 thinking tokens per call on average, up to 526, billed at the output rate.
This note is written from values SugarMount measured itself; an AI coding agent was used to draft it.