---
description: Create account-level custom rulesets using the Rulesets API.
title: Create a custom ruleset using the API
image: https://developers.cloudflare.com/waf/account/custom-rulesets/create-api/og.png?v=860593a02884bff1
---

[Skip to content](#main-content)

> Documentation Index  
> Fetch the complete documentation index at: https://developers.cloudflare.com/waf/llms.txt  
> Use this file to discover all available pages before exploring further.

# Create a custom ruleset using the API

Last updated Sep 8, 2026|Copy as Markdown| [View as Markdown](https://developers.cloudflare.com/waf/account/custom-rulesets/create-api/index.md)| [Agent setup](https://developers.cloudflare.com/agent-setup/)

Note

This feature requires an Enterprise plan.

## Quota limits

Account-level custom rulesets have the following quota limits:

- **Maximum rulesets:** 10
- **Maximum rules per ruleset:** 100
- **Total rule quota:** 1,000 rules across all rulesets on the request path

The total rule quota of 1,000 rules is a hard limit that applies to all plans and cannot be increased. This limit applies across all rulesets that a request traverses, not just account-level custom rulesets.

### Redistribute rules across rulesets

If you need to change the distribution of rules across your rulesets (for example, to create fewer rulesets with more rules per ruleset), contact Cloudflare Support. Only Cloudflare Support can update account-level entitlements to change the ruleset and rule distribution.

Before contacting Support, consider the following optimizations:

- **Consolidate rules:** Combine rules with similar conditions or actions into a single rule with broader matching criteria.
- **Remove unused rules:** Audit your rulesets and remove rules that are no longer triggering or are duplicating functionality.
- **Use IP lists:** Instead of creating multiple rules for individual IP addresses, use [IP lists](https://developers.cloudflare.com/waf/tools/lists/) to group IPs and reference them in a single rule.

To deploy custom rules at the account level:

1. Create a custom ruleset with one or more rules. Alternatively, identify the existing custom ruleset you want to deploy using the [List account rulesets](https://developers.cloudflare.com/api/resources/rulesets/methods/list/) API operation.
2. Deploy the custom ruleset so that it gets executed. To deploy a custom ruleset, create a rule with the `execute` action.

Use the [Rulesets API](https://developers.cloudflare.com/ruleset-engine/rulesets-api/) to work with custom rulesets using the API.

If you are using Terraform, refer to [WAF custom rules configuration using Terraform](https://developers.cloudflare.com/terraform/additional-configurations/waf-custom-rules/#create-and-deploy-a-custom-ruleset).

## Procedure

To deploy a custom ruleset, follow these general steps:

1. Create a custom ruleset in the `http_request_firewall_custom` phase with one or more rules.
2. Deploy the ruleset to the [entry point ruleset](https://developers.cloudflare.com/ruleset-engine/about/rulesets/#entry-point-ruleset) of the `http_request_firewall_custom` phase.

### 1. Create a custom ruleset

The following example creates a custom ruleset at the account level with a single rule in the `rules` array.

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

- <code>Account WAF Write</code>
- <code>Account Rulesets Write</code>

</details>

*Create an account rulesetbash*

```bash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"description": "",
		"kind": "custom",
		"name": "My custom ruleset",
		"rules": [
				{
						"description": "Challenge web traffic (not /api)",
						"expression": "not starts_with(http.request.uri.path, \"/api/\")",
						"action": "managed_challenge"
				}
		],
		"phase": "http_request_firewall_custom"
	}'
```

Save the ruleset ID in the response for the next step.

### 2. Deploy the custom ruleset

To deploy the custom ruleset, add a rule with `"action": "execute"` to the `http_request_firewall_custom` phase entry point ruleset.

1. Invoke the [Get an account entry point ruleset](https://developers.cloudflare.com/api/resources/rulesets/subresources/phases/methods/get/) operation to obtain the definition of the entry point ruleset for the `http_request_firewall_custom` phase. You will need the [account ID](https://developers.cloudflare.com/fundamentals/account/find-account-and-zone-ids/) for this task.<details><summary>

   Required API token permissions</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
   - <code>Account WAF Write</code>
   - <code>Account WAF Read</code>
   - <code>Account Rulesets Read</code>
   - <code>Account Rulesets Write</code></details>

   *Get an account entry point rulesetbash*

   

   ```bash
   curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets/phases/http_request_firewall_custom/entrypoint" \
   	--request GET \
   	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
   ```

   ```json
   {
   	"result": {
   		"description": "Account-level phase entry point",
   		"id": "<RULESET_ID>",
   		"kind": "root",
   		"last_updated": "2024-03-16T15:40:08.202335Z",
   		"name": "root",
   		"phase": "http_request_firewall_custom",
   		"rules": [
   			// ...
   		],
   		"version": "9"
   	},
   	"success": true,
   	"errors": [],
   	"messages": []
   }
   ```


2. If the entry point ruleset already exists (that is, if you received a `200 OK` status code and the ruleset definition), take note of the ruleset ID in the response. Then, invoke the [Create an account ruleset rule](https://developers.cloudflare.com/api/resources/rulesets/subresources/rules/methods/create/) operation to add an `execute` rule to the existing ruleset deploying the custom ruleset. By default, the rule will be added at the end of the list of rules already in the ruleset.

   The following request creates a rule that executes the custom ruleset with ID `<CUSTOM_RULESET_ID>` for all Enterprise zones in the account:<details><summary>

   Required API token permissions</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
   - <code>Account WAF Write</code>
   - <code>Account Rulesets Write</code></details>

   *Create an account ruleset rulebash*

   

   ```bash
   curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets/$RULESET_ID/rules" \
   	--request POST \
   	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
   	--json '{
   		"description": "Execute custom ruleset",
   		"expression": "(cf.zone.plan eq \"ENT\")",
   		"action": "execute",
   		"action_parameters": {
   				"id": "<CUSTOM_RULESET_ID>"
   		},
   		"enabled": true
   	}'
   ```

   Caution

   At the account level, you can only apply custom rulesets to incoming traffic of zones on an Enterprise plan. To enforce this requirement, you must include `cf.zone.plan eq "ENT"` in the expression of the `execute` rule deploying the custom ruleset.
3. If the entry point ruleset does not exist (that is, if you received a `404 Not Found` status code in step 1), create it using the [Create an account ruleset](https://developers.cloudflare.com/api/resources/rulesets/methods/create/) operation. Include a single rule in the `rules` array that executes the custom ruleset for all incoming requests of Enterprise zones in your account.<details><summary>

   Required API token permissions</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
   - <code>Account WAF Write</code>
   - <code>Account Rulesets Write</code></details>

   *Create an account rulesetbash*

   

   ```bash
   curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets" \
   	--request POST \
   	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
   	--json '{
   		"description": "",
   		"kind": "root",
   		"name": "Account-level phase entry point",
   		"rules": [
   				{
   						"action": "execute",
   						"expression": "(cf.zone.plan eq \"ENT\")",
   						"action_parameters": {
   								"id": "<CUSTOM_RULESET_ID>"
   						}
   				}
   		],
   		"phase": "http_request_firewall_custom"
   	}'
   ```



## Next steps

Use the different operations in the [Rulesets API](https://developers.cloudflare.com/ruleset-engine/rulesets-api/) to work with the custom ruleset you created and deployed. The following table has a list of common tasks for working with custom rulesets at the account level:

| Task | Procedure |
| --- | --- |
| Get list of custom rulesets | Use the [List account rulesets](https://developers.cloudflare.com/api/resources/rulesets/methods/list/) operation and search for rulesets with `"kind": "custom"` and `"phase": "http_request_firewall_custom"`. The response will include the ruleset IDs. For more information, refer to [List existing rulesets](https://developers.cloudflare.com/ruleset-engine/rulesets-api/view/#list-existing-rulesets). |
| List all rules in a custom ruleset | Use the [Get an account ruleset](https://developers.cloudflare.com/api/resources/rulesets/methods/get/) operation with the custom ruleset ID to obtain the list of configured rules and their IDs. For more information, refer to [View a specific ruleset](https://developers.cloudflare.com/ruleset-engine/rulesets-api/view/#view-a-specific-ruleset). |
| Update a custom rule | Use the [Update an account ruleset rule](https://developers.cloudflare.com/api/resources/rulesets/subresources/rules/methods/edit/) operation. You will need to provide the custom ruleset ID and the rule ID. For more information, refer to [Update a rule in a ruleset](https://developers.cloudflare.com/ruleset-engine/rulesets-api/update-rule/). |
| Delete a custom rule | Use the [Delete an account ruleset rule](https://developers.cloudflare.com/api/resources/rulesets/subresources/rules/methods/delete/) operation. You will need to provide the custom ruleset ID and the rule ID. For more information, refer to [Delete a rule in a ruleset](https://developers.cloudflare.com/ruleset-engine/rulesets-api/delete-rule/). |

## More resources

For instructions on creating a custom ruleset at the zone level via API, refer to [Custom rulesets (zone level)](https://developers.cloudflare.com/waf/custom-rules/custom-rulesets/).

For more information on working with custom rulesets, refer to [Work with custom rulesets](https://developers.cloudflare.com/ruleset-engine/custom-rulesets/) in the Ruleset Engine documentation.

Was this helpful?

YesNo

## On this page

[![](https://developers.cloudflare.com/_astro/logo.te5VL_aD.svg)Docs](https://developers.cloudflare.com/)

```json
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/waf/account/custom-rulesets/create-api/#page","headline":"Create a custom ruleset using the API","description":"Create account-level custom rulesets using the Rulesets API.","url":"https://developers.cloudflare.com/waf/account/custom-rulesets/create-api/","inLanguage":"en","image":"https://developers.cloudflare.com/waf/account/custom-rulesets/create-api/og.png?v=860593a02884bff1","dateModified":"2026-09-08","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
```
