TL;DR
- Spend Management is now available in Beta for Cloudflare pay-as-you-go customers using Workers and Durable Objects, letting developers set spending thresholds and choose automatic pauses when limits are reached.
- Developers can configure limits and alerts via the dashboard, cf CLI, or REST API, with the system sending email notifications when thresholds or spending caps are reached.
- The feature works alongside AI Gateway spend limits, enabling control over both compute and AI inference costs across applications.
- When a spending limit is hit, Cloudflare pauses only cost-incurring invocations (like Cron Triggers and Queue consumers in Workers) while keeping free operations like static asset serving active.
- Products supported
- Workers and Durable Objects
- Availability
- Beta for all pay-as-you-go
- Access methods
- Dashboard, cf CLI, REST API
What happened
Cloudflare has introduced Spend Management in Beta, a feature that addresses one of the most frequently requested capabilities from its developer community. The system enables pay-as-you-go customers to set spending thresholds and configure automatic pauses when those limits are reached, preventing unexpected bills from unplanned usage. While Cloudflare previously offered usage notifications and budget alerts for paid plans, the company notes that informing customers about spending is not the same as actively controlling it. With more than 10 million developers building on Cloudflare, demand for spending controls has become increasingly urgent.
How to use Spend Management
Developers can enable Spend Management through three interfaces: the Cloudflare dashboard, the cf CLI, or the REST API. In the dashboard, the feature is located under Manage Account > Billing > Spend limits. When enabling controls on a product, users define a spending limit, specify a recipient email for notifications, and set one or more alert thresholds. Cloudflare will send email notifications when evaluated spend reaches a configured threshold or when the spending limit is reached. The dashboard displays billing cycle costs for each supported product in near real-time, with updates occurring within 10 minutes.
The billing cycle begins when the paid subscription starts, not when a Worker is deployed or a spending cap is created. This means a subscription starting October 10 runs from October 10 to November 10, rather than following a calendar month. The dashboard also includes an audit log showing who changed a limit, when changes occurred, and when caps were reached.
Once a spending cap is enforced, new invocations of that product are rejected. However, Cloudflare only pauses customer-code invocations that incur costs. In Workers, for example, Cron Triggers and Queue consumer invocations are paused, but static assets continue to be served. To resume service, customers 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 existing block expires.
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"
}'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"
}'Integration with AI Gateway
Spend Management works alongside AI Gateway spend limits to manage compute and AI inference costs across applications. AI Gateway already supports per-user and per-model budgets for Workers AI and other AI providers, applied to requests routed through the gateway. This allows developers to maintain granular cost control across different aspects of their infrastructure.
Technical architecture
Building Spend Management at Cloudflare's scale required multiple teams, changes to existing systems, and creation of new infrastructure. The system uses a two-stage metering pipeline that collects and aggregates usage measurements close to their source, reducing raw event volume before downstream processing. Each metering parser converts raw events into usage measurements and combines matching measurements into one-minute buckets. A second stage merges these partial aggregates using the same grouping rules over typically five-minute windows, further reducing volume before the Usage Engine processes them.
The Usage Engine translates aggregated measurements into standardized usage records containing the account, usage window, metric, quantity, and relevant dimensions. Processing is partitioned by account, so an account's usage and subscription information meet in the same place. This allows Cloudflare to maintain accumulated usage and apply included allowances without coordinating across pricing processors on every update. Each partition maintains both local state for fast access and a durable write-ahead logging changelog on disk.
The Rating Engine turns usage into monetary value by bringing together usage records (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). Usage and subscription updates arrive as independent streams, so if usage arrives before the subscription information needed to price it, the system retains it as pending and revisits it when that information becomes available. Once accumulated spend is calculated, the system evaluates whether warning or blocking thresholds have been reached and sends notifications if configured.
Cap enforcement is asynchronous and does not sit in the request path. The policy service sends caps to Cloudflare's runtime configuration service and Quicksilver, its internal key-value store, which propagates the information to all nodes. Once the cap reaches Quicksilver, the runtime picks it up during periodic refresh and starts rejecting capped invocations. By using local state, requests never have to wait on the Rating Engine.
Current support and future plans
Spend Management is currently available for Workers and Durable Objects, with other Cloudflare products to follow. The feature is designed to be easy to extend to additional products as the company continues expanding its offering.
Source
Cloudflare Bloghttps://blog.cloudflare.com/spend-management/AI-assisted, verified against the source. This post was drafted with AI from the primary source linked above and checked automatically against it. For anything you depend on, read the original.
- #cloudflare
- #costmanagement
- #workers
- #billing
- #devops

