---
title: "Create an edge rule"
method: POST
path: "/projects/{project_id}/edge-rules"
tags: ["Edge Rules"]
---

# Create an edge rule

`POST /projects/{project_id}/edge-rules`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/projects/{project_id}/edge-rules`
- Auth: HTTP bearer

The rule is enforced by every proxy within seconds. Create it with
`mode: log_only` to watch what it would match before it acts.

## Path parameters

- `project_id` integer, required

## Request body

- CreateEdgeRuleRequest: Body for creating a rule.
  - `action` union, required: What a matching rule does.
    - object: Return an error response. Status 400–499.
      - `body` string: Plain-text body, up to 1024 bytes. Empty for a short default.
      - `status` integer, required
      - `type` 'block', required
    - object: Skip the remaining edge rules. Rate limits, attack mode and password protection still apply.
      - `type` 'allow', required
    - object: Serve the proof-of-work challenge unless the visitor holds clearance.
      - `type` 'challenge', required
    - object: Redirect to a path or an absolute URL with a fixed host. `{path}` and `{query}` insert the visitor's normalized path and raw query string.
      - `status` integer, required
      - `target` string, required
      - `type` 'redirect', required
    - object: Record the match and keep evaluating.
      - `type` 'log', required
  - `enabled` boolean
  - `environment_id` integer, nullable
  - `expression` EdgeRuleGroup, required: A group of conditions and nested groups.
    - `children` EdgeRuleExpression[]
      - union: A node of a rule's match expression.
        - object: A single test against one request attribute.
          - `case_insensitive` boolean: Compare without case. Hosts, methods, countries and enumerated fields always compare without case.
          - `field` 'ip' | 'country' | 'continent' | 'asn' | 'is_hosting_provider' | 'host' | 'path' | 'raw_path' | 'method' | 'query' | 'header' | 'cookie' | 'user_agent' | 'ja4' | 'bot_class', required: A request attribute a condition tests.
          - `id` string: Node identifier, unique within the rule. Assigned by the server when empty; used to attach validation messages to the right condition.
          - `key` string, nullable: Header, query parameter or cookie name. Required for those fields.
          - `op` 'eq' | 'in' | 'in_cidr' | 'starts_with' | 'ends_with' | 'contains' | 'glob' | 'regex' | 'exists' | 'not_exists', required: How a condition compares the request value with its `values`.
          - `values` string[]: One value for single-value operators, a list for `in`/`in_cidr`, none for `exists`/`not_exists`.
          - `kind` 'condition', required
        - object: A group of conditions and nested groups.
          - `children` EdgeRuleExpression[]
          - `combinator` 'all' | 'any' | 'none', required: How a group combines its children. `none` is `not(any(...))`.
          - `id` string
          - `kind` 'group', required
    - `combinator` 'all' | 'any' | 'none', required: How a group combines its children. `none` is `not(any(...))`.
    - `id` string
  - `mode` 'enforce' | 'log_only': `enforce` acts on matches; `log_only` (the default) records them without acting, so a new rule can be watched before it enforces.
  - `name` string, nullable: Up to 80 characters. Left empty, a name is generated from the rule, e.g. "Block when path starts with /admin".
  - `position` integer, nullable: Where to insert the rule (0 = first). Defaults to the end.

## Response `201`

Rule created

- EdgeRuleResponse: One stored rule.
  - `action` union, required: What a matching rule does.
    - object: Return an error response. Status 400–499.
      - `body` string: Plain-text body, up to 1024 bytes. Empty for a short default.
      - `status` integer, required
      - `type` 'block', required
    - object: Skip the remaining edge rules. Rate limits, attack mode and password protection still apply.
      - `type` 'allow', required
    - object: Serve the proof-of-work challenge unless the visitor holds clearance.
      - `type` 'challenge', required
    - object: Redirect to a path or an absolute URL with a fixed host. `{path}` and `{query}` insert the visitor's normalized path and raw query string.
      - `status` integer, required
      - `target` string, required
      - `type` 'redirect', required
    - object: Record the match and keep evaluating.
      - `type` 'log', required
  - `created_at` string, date-time, required
  - `enabled` boolean, required
  - `environment_id` integer, nullable: `null` applies the rule to every environment of the project.
  - `expression` EdgeRuleGroup, required: A group of conditions and nested groups.
    - `children` EdgeRuleExpression[]
      - union: A node of a rule's match expression.
        - object: A single test against one request attribute.
          - `case_insensitive` boolean: Compare without case. Hosts, methods, countries and enumerated fields always compare without case.
          - `field` 'ip' | 'country' | 'continent' | 'asn' | 'is_hosting_provider' | 'host' | 'path' | 'raw_path' | 'method' | 'query' | 'header' | 'cookie' | 'user_agent' | 'ja4' | 'bot_class', required: A request attribute a condition tests.
          - `id` string: Node identifier, unique within the rule. Assigned by the server when empty; used to attach validation messages to the right condition.
          - `key` string, nullable: Header, query parameter or cookie name. Required for those fields.
          - `op` 'eq' | 'in' | 'in_cidr' | 'starts_with' | 'ends_with' | 'contains' | 'glob' | 'regex' | 'exists' | 'not_exists', required: How a condition compares the request value with its `values`.
          - `values` string[]: One value for single-value operators, a list for `in`/`in_cidr`, none for `exists`/`not_exists`.
          - `kind` 'condition', required
        - object: A group of conditions and nested groups.
          - `children` EdgeRuleExpression[]
          - `combinator` 'all' | 'any' | 'none', required: How a group combines its children. `none` is `not(any(...))`.
          - `id` string
          - `kind` 'group', required
    - `combinator` 'all' | 'any' | 'none', required: How a group combines its children. `none` is `not(any(...))`.
    - `id` string
  - `hits` integer, required: Requests this rule has matched, across every proxy. Counters are flushed every few seconds.
  - `id` integer, required
  - `last_hit_at` string, date-time, nullable
  - `mode` 'enforce' | 'log_only', required: `log_only` evaluates the rule and records matches but never acts.
  - `name` string, required
  - `position` integer, required: 0-based evaluation order. The first rule that decides wins.
  - `project_id` integer, required
  - `revision` integer, required: Edit counter. Send it back on update so a concurrent change is refused instead of overwritten.
  - `summary` string, required: The rule in one sentence, e.g. "Block with 403 when path starts with /admin".
  - `updated_at` string, date-time, required

## Other responses

- `400`: Invalid rule; `issues` lists each problem
- `401`: Unauthorized
- `403`: Insufficient permissions
- `404`: Project or environment not found
- `409`: The project already has 100 rules
- `500`: Internal server error

## Changes

- **2026-11-09** `12896146b193`: 6 breaking
  - removed the required property `extensions` from the response with the `400` status
  - removed the required property `extensions` from the response with the `401` status
  - removed the required property `extensions` from the response with the `403` status
  - removed the required property `extensions` from the response with the `404` status
  - …2 more
- **2026-10-31** `c2d57aea4875`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/projects/:project_id/edge-rules/post.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
