Developers building on Cloudflare's platform have long asked for better ways to control spending, and the company is responding. With more than 10 million developers now using Cloudflare, the demand for cost controls has only grown. While usage notifications and budget alerts have existed for paid plans, they only inform—they don't prevent unexpected bills. Cloudflare is now introducing Spend Management in beta for pay-as-you-go customers, starting with Workers and Durable Objects.

The new feature lets developers set spending thresholds and configure Cloudflare to pause activity when those limits are reached, preventing runaway costs from unplanned usage. Spend Management works alongside AI Gateway's existing per-user and per-model budgets, giving teams a unified way to manage compute and AI inference expenses across their applications.

How it works

Developers can enable Spend Management through the dashboard, the cf CLI, or the REST API. In the dashboard, the feature lives under Manage Account > Billing > Spend limits. Once enabled for a product, users define a spending limit, specify a recipient email for alerts, and set one or more alert thresholds.

When a recipient email is configured, Cloudflare sends notifications as spending reaches each threshold or hits the limit itself. Upon reaching the limit, a blocking policy takes effect and the product pauses automatically. The dashboard displays current billing cycle costs for each supported product in near real time—under 10 minutes—and lets users manage settings and thresholds from a single view. An audit log tracks who changed limits and when caps were enforced.

Enabling Spend management for Durable Objects

It's important to note that the billing cycle begins when a paid subscription starts, not when a Worker deploys or a spending cap is created. A subscription beginning October 10 runs from October 10 to November 10, not by calendar month.

Email notification when the spending limit is reached

Like most Cloudflare services, Spend Management is available as an API for programmatic use. Here's an example using curl:

curl --fail-with-body --request POST \
  "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/billing/spend-policies" \
  --header "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "Workers spending cap",
    "product_id": "workers",
    "enabled": true,
    "threshold_cents": 10000,
    "action": "usage_block",
    "notification_email": "me@example.com"
  }'

The cf CLI also supports Spend Management operations:

cf billing spend-policies list
cf billing spend-policies create
cf billing spend-policies get
cf billing spend-policies update
cf billing spend-policies delete
cf billing spend-policies audit list
cf billing spend-policies activity list

cf billing spend-policies create --body '{
  "name": "Workers spending cap",
  "product_id": "workers",
  "enabled": true,
  "threshold_cents": 10000,
  "action": "usage_block",
  "notification_email": "me@example.com"}'

Once a cap is enforced, new invocations of that product are rejected. Cloudflare pauses only customer-code invocations that incur costs—in Workers, for example, Cron Triggers and Queue consumer invocations stop, but static assets continue to be served.

To lift a cap, developers can raise the limit above the current cycle's accumulated spend, disable or delete the blocking policy, or wait until the next billing cycle when the block expires automatically.

How we built Spend Management

Building a cost-control system at Cloudflare's scale required coordination across multiple teams, modifications to existing systems, and creation of entirely new infrastructure. The architecture moves from raw invocation events across the distributed network to a global blocking decision applied everywhere.

Collecting and aggregating close to the source

Each invocation generates usage measurements—requests, CPU time, execution duration, or storage operations depending on the product. Transporting and processing raw data from all sources to the rating engine would not scale efficiently, so Cloudflare collects and aggregates measurements as close to the source as possible using a two-stage metering pipeline.

The life of a capped billable event

The first stage reduces raw-event volume near the parsing point into one-minute windows. Metering parsers convert raw events into usage measurements and combine matching measurements into typically one-minute buckets. Multiple records can still describe the same account and time window.

The second stage uses a separate service to merge first-stage partial aggregates using the same grouping rules over typically five-minute windows, further reducing volume before the Usage Engine processes it. Consolidated aggregates are also archived, creating a durable dataset for later analytics and reconciliation.

This two-stage approach reduces raw event volume early, allowing downstream engines to process only the aggregated usage needed to calculate spend and enforce caps. This design makes the system practical at Cloudflare's scale.

Usage Engine: account-partitioned processing

How we collect, parse, and aggregate data before sending it to the rating engine

The Usage Engine translates aggregated measurements into usage records—standardized records containing the account, usage window, metric, quantity, and relevant dimensions. It maps product-specific meters into supported usage metrics.

Processing is partitioned by account, so each account's usage and subscription information coexist in the same place. This allows the system to maintain accumulated usage and apply included allowances without coordinating across pricing processors on every update.

Different partitions run in parallel, spreading work across accounts while keeping each account's pricing state together. Each partition maintains both local state for fast access and a durable write-ahead logging (WAL) changelog on disk. This architecture provides:

  • Less cross-partition coordination: each account's usage and subscription state remain together.
  • Consistent pricing: usage updates share the same allowance and accumulated-spend state.
  • Parallel processing: different partitions calculate spend independently.
  • Recoverability: durable state lets replacement processors rebuild and resume after failures.
Account-partitioned processing in the Usage Engine

Usage metrics then flow into the Rating Engine.

The Rating Engine

The Rating Engine is the core of Spend Management, converting usage into monetary value and answering the question: "Given what this account has consumed, its subscription, and its pricing, how much has it spent so far?"

The Rating Engine brings together three components: usage records (quantities such as requests and CPU milliseconds), subscription information (the account's billing period and plan changes), and pricing rules (rates, included allowances, and billing rounding).

High-level overview of the Rating Engine, the brains of Spend Management

Usage and subscription updates arrive as independent streams, so the Rating Engine cannot assume they reach it in order. The system must also recover from data processing failures or missing subscription information from failed webhooks. If usage arrives before the subscription information needed to price it, the engine retains it as pending and revisits it when that information becomes available. This approach tolerates temporary delays without treating unpriced usage as free.

The Rating Engine calculates and tracks accumulated spend using a product catalog database that defines usage metrics, including allowances, rates, and rounding rules, alongside the account's subscription information. One million CPU milliseconds doesn't automatically incur a charge; the engine first applies the account's included CPU allowance, then prices any excess. It prices accumulated usage rather than rounding and charging for each request independently.

After accumulated spend is calculated, two steps follow: policy evaluation determines whether one or more warning or blocking thresholds have been reached, and reporting displays estimated usage charges in the dashboard via APIs and sends email alerts through Cloudflare Email Service if necessary.

Asynchronous cap enforcement

The Rating Engine does not sit in the request path or directly reject requests. Instead, the policy service sends the cap to the runtime configuration service and Quicksilver, Cloudflare's internal key-value store built for fast global replication and low-latency access at planet scale. This propagates caps to all nodes asynchronously.

Once a cap reaches Quicksilver, the runtime picks it up during periodic refresh and begins rejecting capped invocations or operations. Enforcement uses local state, so requests never wait on the Rating Engine. By reusing existing runtime account-limit architecture, Cloudflare keeps rating out of the request path while distributing caps across the global network.

What's next

Any pay-as-you-go customer can start using Spend Management today. While this represents a major milestone, it is also just the beginning. Cloudflare has outlined plans for the coming weeks and months.

More products

Spend Management launches with caps for Workers and Durable Objects, but will expand to many other Cloudflare products and primitives in the near future. The system was built to make onboarding straightforward and familiar for products, so expect the catalog to grow.

Closer to real time

While near real time under 10 minutes is a solid benchmark, Cloudflare plans to reduce that gap further. The team has ideas for shortening the time between measurement and enforcement, with a goal of under a minute.

Agent and application-based budgets

Currently, Spend Management measures spend by products and primitives, but other useful dimensions exist for cost control. A developer might want to monitor the costs of a specific application—such as a Worker script using R2 or Workers AI—and pause that application rather than disabling underlying primitives across all customer applications.

AI agents present another compelling use case. Unconstrained agents can enter recursive reasoning loops to brute-force problems, generating thousands of dollars in costs from high-frequency, expensive API calls while also causing denial-of-service issues on databases and other services. AI Gateway already supports per-agent budgets for AI requests routed through it. Tasks also consume compute, database, and storage resources, and Cloudflare wants to enable budgeting for that broader resource use across products.

Developers will be able to tag calls from agents, and the pipeline will carry that metadata from the runtime through to the Rating Engine. This will allow the system to attribute spend and pause an application or agentic task across products without interrupting other unrelated applications.

Get started

This launch is a first step toward making spend controls a standard part of building on Cloudflare, alongside deploying code and monitoring applications. Developers can check the billing developer documentation for more information and start using Spend Management today. Feedback on what works, what's missing, or where more granular budgets would help is welcome. Join Cloudflare on Discord or social media—the team is listening.