---
title: "Create an AI custom rule"
method: POST
path: "/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules"
tags: ["Static Analysis"]
---

# Create an AI custom rule

`POST /api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules`

Create a new AI custom rule within a ruleset.

## Path parameters

- `ruleset_name` string, required

## Request body

- AiCustomRuleRequest — Request body for creating an AI custom rule.
  - `data` AiCustomRuleRequestData — Request data for creating an AI custom rule.
    - `attributes` AiCustomRuleRequestAttributes — Attributes for creating an AI custom rule.
      - `name` string — The rule name.
    - `id` string — The rule identifier, which must match the name.
    - `type` 'ai_rule' — AI custom rule resource type.

## Response `200`

Successfully created

- AiCustomRuleResponse — Response containing a single AI custom rule.
  - `data` AiCustomRuleResponseData, required — Response data for an AI custom rule.
    - `attributes` AiCustomRuleItem, required — An AI custom rule embedded within a ruleset response.
      - `created_at` string, date-time, required — The creation timestamp.
      - `created_by` string, required — The identifier of the user who created the rule.
      - `last_revision` AiCustomRuleRevisionResponseAttributes, required — Response attributes of an AI custom rule revision.
        - `category` 'SECURITY' | 'BEST_PRACTICES' | 'CODE_STYLE' | 'ERROR_PRONE' | 'PERFORMANCE', required — Rule category
        - `checksum` string, required — Checksum of the revision content.
        - `content` string, required — Base64-encoded AI model content for this revision.
        - `created_at` string, date-time, required — The creation timestamp.
        - `created_by` string, required — The identifier of the user who created the revision.
        - `cwe` string, nullable, required — The associated CWE identifier.
        - `description` string, required — Base64-encoded full description.
        - `directories` string[], required — Directory patterns this rule applies to.
        - `execution_mode` 'auto' | 'manual' | 'always', required — The execution mode for an AI rule revision.
        - `globs` string[], required — File glob patterns this rule applies to.
        - `is_default` boolean, required — Whether this is a default Datadog rule.
        - `is_published` boolean, required — Whether this revision is published.
        - `is_testing` boolean, required — Whether this revision is for testing only.
        - `severity` 'ERROR' | 'WARNING' | 'NOTICE', required — Rule severity
        - `short_description` string, required — Base64-encoded short description.
        - `version_id` integer, required — The version identifier for this revision.
      - `name` string, required — The rule name.
    - `id` string, required — The rule identifier.
    - `type` 'ai_rule', required — AI custom rule resource type.

## Other responses

- `400` — Bad Request
- `401` — Unauthorized
- `409` — Conflict - rule already exists
- `412` — Precondition Failed - validation error or ruleset not found
- `429` — Too many requests
- `500` — Internal Server Error

---

[API](https://skmtc.dev/datadog/apis/api-v2.md) · [All operations](https://skmtc.dev/datadog/apis/api-v2/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/datadog/api-v2/revisions/da68bf029e4c/schema)
