What Costbrake reads from Cloudflare
Costbrake reads usage from Cloudflare's GraphQL Analytics API: Workers requests and CPU time, static assets, Durable Objects, KV, R2, D1, Queues, Workers AI, Vectorize, Containers, Browser Rendering, Workflows, Workers Builds, Images and Stream. It prices that usage at Cloudflare's list prices, net of what your plan includes each month, so you see dollars within minutes instead of the next day.
About a day later, the billed daily dollars from Cloudflare billing replace the estimate. Those need a token with Billing Read on a pay-as-you-go account. Enterprise contracts get the usage estimate only, and Workers Logs charges only show up in the billed dollars, because Cloudflare has no live counter for them. If you connect by signing in with Cloudflare instead of pasting a token, Costbrake gets the usage estimate only.
How fast a Cloudflare spike reaches you
Cloudflare's analytics run about 3 minutes behind live traffic. On Pro and Team, Costbrake checks every 5 minutes, so a jump in Workers requests or R2 operations shows up within minutes. Once a spike alert fires, that connection checks every minute for the next 2 hours. On Free, checks run once an hour and alerts go out by email.
Alerts go to email on every plan, and to Slack, Discord or a webhook on Pro and Team. Team adds PagerDuty.
Cloudflare's own controls, and where Costbrake fits
Cloudflare has two kinds of alerts and one hard stop, the spend policy. The table shows what each one does next to Costbrake.
| Control | What it does | Stops spend? |
|---|---|---|
| Budget alert | Emails your recipients once when account-wide usage spend crosses a dollar amount you set | No, Cloudflare calls budget alerts informational only |
| Usage notification | Notifies you when one product, like Workers requests, crosses a usage threshold | No, it only notifies |
| Spend policy with a usage block | Blocks further use of one product until the billing period ends, once spend reaches the threshold | Yes, for that product on the whole account |
| Costbrake | Checks every 5 minutes on Pro and Team, alerts on spikes, and offers 8 brakes for one Worker, queue, bucket or product | Only when an admin runs a brake |
Cloudflare allows one enabled usage block per product on an account. Raising the threshold above the current balance, disabling the policy or deleting it lifts the block early. Costbrake's Undo puts your old policy back or turns off the one it added, so the block lifts. The Cloudflare spending limit guide covers setting one up by hand.
The token and permissions Costbrake asks for
Alerts need an account API token with only Account Analytics Read and Billing Read. Costbrake opens Cloudflare's token page with those two filled in, and it refuses a token that can also reach Workers or API tokens.
Brakes use a second token, or one click on Authorize brakes if you signed in with Cloudflare. That needs Workers Scripts Edit. Queues Edit, Workers Routes Edit with Zone Read, and Workers R2 Storage Edit each unlock one more brake. Blocking Workers spend needs Billing Edit, which the pre-filled link leaves out because it can also change your plan, and sign-in can't grant it. Costbrake refuses a brake token that can also reach DNS, API tokens or Tunnels.
Costbrake switches things off and back on. It never uploads code and never deletes Workers, buckets or zones.
What visitors see after a CPU cap
The CPU cap sets a 50 ms limit on one Worker. Requests that need more fail with error 1102, which Cloudflare describes as a Worker that has exceeded its CPU time limit or memory limit. On the Workers Paid plan the default limit is 30 seconds and the most you can set is 5 minutes. Undo puts back the limit the Worker had before.
Cheap requests keep working under the cap, so it suits a Worker whose CPU bill is climbing on a few heavy routes. The Cloudflare Workers pricing guide shows what CPU time costs past the included amount.
Questions and answers
Can Costbrake stop a Cloudflare bill on its own?
No. Costbrake alerts you and offers 8 brakes, but a brake only runs when an admin starts it and confirms it. If you want Cloudflare itself to block spend, a spend policy with a usage block does that per product, and Costbrake can add one for Workers or Durable Objects when an admin runs that brake.
Does Costbrake need write access to my Cloudflare account?
Not for alerts. The read token has Account Analytics Read and Billing Read only. Write access is only for brakes, through a second token or Authorize brakes, after an admin turns the killswitch on for that connection.
How quickly does Costbrake see a Cloudflare spike?
Cloudflare's analytics run about 3 minutes behind. Costbrake checks every 5 minutes on Pro and Team and every hour on Free. After a spike alert, Pro and Team check every minute for the next 2 hours.
Why do Costbrake's Cloudflare numbers change a day later?
The first numbers are usage times Cloudflare's list price, net of your included usage. About a day later the billed daily dollars from Cloudflare replace them, on pay-as-you-go accounts with a token that has Billing Read.
What does the spend policy brake block?
It adds a Cloudflare spend policy that blocks Workers or Durable Objects on the whole account once this billing period's spend on that product reaches $0.01, until the period ends. If you already have a usage block, Costbrake lowers its limit instead. Undo restores your policy or turns off the one Costbrake added.
Sources
Updated