Cloudflare integration

Cloudflare spend alerts and brakes for Workers, Queues and R2

Costbrake checks your Cloudflare usage every 5 minutes on Pro and Team, about 3 minutes behind Cloudflare's own analytics, and alerts you when Workers, R2, D1 or another metered product spikes. After a spike alert it checks every minute for the next 2 hours.

When an alert lands, an admin can run one of 8 brakes, from pausing a Worker's cron triggers to a Cloudflare spend policy that blocks Workers for the rest of the billing period. Every brake has an Undo. Brakes come with Pro and Team, see pricing.

Cloudflare at a glance

Reads
Usage for Workers, Durable Objects, KV, R2, D1, Queues, Workers AI and more at list price, then billed daily dollars
Key
A read-only API token with Account Analytics Read and Billing Read, or sign in with Cloudflare
Setup
Click Authorize after signing in with Cloudflare, paste a pre-filled token, or let your AI agent do it
Free plan
Hourly checks and email alerts, no brakes
Pro and Team
Checks every 5 minutes, Slack, Discord and webhook alerts, PagerDuty on Team, all 8 brakes
Spike checks
Every minute for 2 hours after a spike alert
Brakes
8, each started and confirmed by an admin, each with an Undo

Brakes

8 brakes for Cloudflare

An admin picks a brake, confirms it, and can undo it later. Brakes come with Pro and Team.

  • Admin confirms

    Turn off workers.dev and preview URLs

    Turns off the public workers.dev URL and the preview URLs of one Worker.

    UndoRestores the workers.dev and preview URL settings the Worker had before.

    Custom domains, routes, crons and queue consumers keep running.

  • Admin confirms

    Pause queue delivery

    Stops delivering messages from one queue to its consumer Worker.

    UndoResumes delivery, and the queued messages are delivered again.

    Producers can still send, and messages stay in the queue until their retention period ends.

  • Admin confirms

    Pause cron triggers

    Removes the cron triggers of one Worker so scheduled runs stop, without touching its code.

    UndoPuts the saved cron schedules back.

  • Admin confirms

    Detach custom domains and routes

    Detaches the custom domains of one Worker and clears its routes, so requests on those hostnames stop reaching it.

    UndoReattaches the saved domains and routes, and leaves alone any that now point at another Worker.

    Cloudflare removes the DNS record it made for each custom domain, requests on a cleared route go to your origin if you have one, and Costbrake checks up to 15 zones.

  • Admin confirms

    Roll back to the previous version

    Deploys the previous version of one Worker to all traffic, like wrangler rollback.

    UndoRedeploys the versions that were live before the brake, unless the Worker was deployed again since.

    Cloudflare refuses the rollback when secrets, bindings or Durable Object classes changed since that version.

  • Admin confirms

    Cap CPU time per request

    Sets a 50 ms CPU limit on one Worker, so expensive requests fail with error 1102 instead of running up CPU charges.

    UndoRestores the CPU limit the Worker had before, or the 30-second default.

    Needs the Workers Paid plan, and Cloudflare saves the change as a new version.

  • Admin confirms

    Turn off the r2.dev URL

    Turns off the public r2.dev URL of one R2 bucket.

    UndoTurns the r2.dev URL back on.

    Custom domains, Workers bindings and the S3 API keep working.

  • Admin confirms

    Block usage with a spend policy

    Adds a Cloudflare spend policy that blocks Workers or Durable Objects on the whole account once this billing period's spend on it reaches $0.01, until the period ends.

    UndoPuts your spend policy back as it was, or turns off the one Costbrake added.

    Needs a brake token with Billing Edit, and if you already have a usage block, Costbrake lowers its limit instead.

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.

ControlWhat it doesStops spend?
Budget alertEmails your recipients once when account-wide usage spend crosses a dollar amount you setNo, Cloudflare calls budget alerts informational only
Usage notificationNotifies you when one product, like Workers requests, crosses a usage thresholdNo, it only notifies
Spend policy with a usage blockBlocks further use of one product until the billing period ends, once spend reaches the thresholdYes, for that product on the whole account
CostbrakeChecks every 5 minutes on Pro and Team, alerts on spikes, and offers 8 brakes for one Worker, queue, bucket or productOnly 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

Start with 14 days of Pro, free

Catch the next Cloudflare spike before the invoice.

14 days of Pro, then Free for 2 accounts. No card needed.