---
title: Create an AI custom rule revision
description: Create a new revision for an AI custom rule.
breadcrumbs: ドキュメント > API > Create an AI custom rule revision
---

> For the complete documentation index, see [llms.txt](https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/llms.txt).

# Create an AI custom rule revision

## v2 (latest)

{% alert level="warning" %}
**Note**: This endpoint is in preview and is subject to change.
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help.md).
{% /alert %}

| Datadog site      | API endpoint                                                                                                     |
| ----------------- | ---------------------------------------------------------------------------------------------------------------- |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules/{rule_name}/revisions     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules/{rule_name}/revisions |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules/{rule_name}/revisions |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules/{rule_name}/revisions      |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules/{rule_name}/revisions |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules/{rule_name}/revisions |
| uk1.datadoghq.com | POST https://api.uk1.datadoghq.com/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules/{rule_name}/revisions |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules/{rule_name}/revisions      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/static-analysis/ai/rulesets/{ruleset_name}/rules/{rule_name}/revisions  |

### Overview

Create a new revision for an AI custom rule.

### Arguments

#### Path Parameters

| Field                     | Type   | Description       |
| ------------------------- | ------ | ----------------- |
| ruleset_name [*required*] | string | The ruleset name. |
| rule_name [*required*]    | string | The rule name.    |

### Request

#### Body Data (required)

{% tabs %}
{% tab label="Model" %}
| Parent field | Field                          | Type     | Description                                                                                                  |
| ------------ | ------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------ |
|              | data                           | object   | Request data for creating an AI custom rule revision.                                                        |
| data         | attributes                     | object   | Attributes for creating an AI custom rule revision.                                                          |
| attributes   | category [*required*]          | enum     | Rule category Allowed enum values: `SECURITY`, `BEST_PRACTICES`, `CODE_STYLE`, `ERROR_PRONE`, `PERFORMANCE`. |
| attributes   | content [*required*]           | string   | Base64-encoded AI model content for this revision.                                                           |
| attributes   | cwe                            | string   | The associated CWE identifier.                                                                               |
| attributes   | description [*required*]       | string   | Base64-encoded full description.                                                                             |
| attributes   | directories [*required*]       | [string] | Directory patterns this rule applies to.                                                                     |
| attributes   | execution_mode [*required*]    | enum     | The execution mode for an AI rule revision. Allowed enum values: `auto`, `manual`, `always`.                 |
| attributes   | globs [*required*]             | [string] | File glob patterns this rule applies to.                                                                     |
| attributes   | is_published [*required*]      | boolean  | Whether this revision is published.                                                                          |
| attributes   | is_testing [*required*]        | boolean  | Whether this revision is for testing only.                                                                   |
| attributes   | severity [*required*]          | enum     | Rule severity Allowed enum values: `ERROR`, `WARNING`, `NOTICE`, `NONE`.                                     |
| attributes   | short_description [*required*] | string   | Base64-encoded short description.                                                                            |
| attributes   | version_id                     | int64    | The version identifier for this revision.                                                                    |
| data         | id                             | string   | The revision identifier.                                                                                     |
| data         | type                           | enum     | AI custom rule revision resource type. Allowed enum values: `ai_rule_revision`.                              |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "category": "SECURITY",
      "content": "Content",
      "cwe": "79",
      "description": "Ruleset description",
      "directories": [
        []
      ],
      "execution_mode": "auto",
      "globs": [
        "**/*.py"
      ],
      "is_published": false,
      "is_testing": false,
      "severity": "ERROR",
      "short_description": "Ruleset short description",
      "version_id": 1
    },
    "id": "revision-abc-123",
    "type": "ai_rule_revision"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="200" %}
Successfully created
{% /tab %}

{% tab label="400" %}
Bad Request

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="401" %}
Unauthorized

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="404" %}
Rule not found

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too many requests

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="500" %}
Internal Server Error

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
# Path parameters
export ruleset_name="my-ai-ruleset"
export rule_name="my-ai-rule"

# Set your Datadog site and credentials
export DD_SITE="datadoghq.com" # Or us3.datadoghq.com, us5.datadoghq.com, datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com, uk1.datadoghq.com, ddog-gov.com, us2.ddog-gov.com
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/static-analysis/ai/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "category": "SECURITY",
      "content": "Content",
      "description": "Ruleset description",
      "directories": [],
      "execution_mode": "auto",
      "globs": [
        "**/*.py"
      ],
      "is_published": false,
      "is_testing": false,
      "severity": "ERROR",
      "short_description": "Ruleset short description",
      "version_id": 1
    },
    "id": "revision-abc-123",
    "type": "ai_rule_revision"
  }
}
EOF
```
{% /tab %}

{% tab label="Go" %}
```go
// Create an AI custom rule revision returns "Successfully created" response

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.AiCustomRuleRevisionRequest{
		Data: &datadogV2.AiCustomRuleRevisionRequestData{
			Attributes: &datadogV2.AiCustomRuleRevisionRequestAttributes{
				Category:      datadogV2.CUSTOMRULEREVISIONATTRIBUTESCATEGORY_SECURITY,
				Content:       "Content",
				Cwe:           *datadog.NewNullableString(datadog.PtrString("79")),
				Description:   "Ruleset description",
				Directories:   []string{},
				ExecutionMode: datadogV2.AICUSTOMRULEREVISIONEXECUTIONMODE_AUTO,
				Globs: []string{
					"**/*.py",
				},
				IsPublished:      false,
				IsTesting:        false,
				Severity:         datadogV2.CUSTOMRULEREVISIONATTRIBUTESSEVERITY_ERROR,
				ShortDescription: "Ruleset short description",
				VersionId:        datadog.PtrInt64(1),
			},
			Id:   datadog.PtrString("revision-abc-123"),
			Type: datadogV2.AICUSTOMRULEREVISIONDATATYPE_AI_RULE_REVISION.Ptr(),
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
	configuration := datadog.NewConfiguration()
	configuration.SetUnstableOperationEnabled("v2.CreateAiCustomRuleRevision", true)
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewStaticAnalysisApi(apiClient)
	r, err := api.CreateAiCustomRuleRevision(ctx, "my-ai-ruleset", "my-ai-rule", body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `StaticAnalysisApi.CreateAiCustomRuleRevision`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"
```
{% /tab %}

{% tab label="Java" %}
```java
// Create an AI custom rule revision returns "Successfully created" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.StaticAnalysisApi;
import com.datadog.api.client.v2.model.AiCustomRuleRevisionDataType;
import com.datadog.api.client.v2.model.AiCustomRuleRevisionExecutionMode;
import com.datadog.api.client.v2.model.AiCustomRuleRevisionRequest;
import com.datadog.api.client.v2.model.AiCustomRuleRevisionRequestAttributes;
import com.datadog.api.client.v2.model.AiCustomRuleRevisionRequestData;
import com.datadog.api.client.v2.model.CustomRuleRevisionAttributesCategory;
import com.datadog.api.client.v2.model.CustomRuleRevisionAttributesSeverity;
import java.util.Collections;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
    defaultClient.setUnstableOperationEnabled("v2.createAiCustomRuleRevision", true);
    StaticAnalysisApi apiInstance = new StaticAnalysisApi(defaultClient);

    AiCustomRuleRevisionRequest body =
        new AiCustomRuleRevisionRequest()
            .data(
                new AiCustomRuleRevisionRequestData()
                    .attributes(
                        new AiCustomRuleRevisionRequestAttributes()
                            .category(CustomRuleRevisionAttributesCategory.SECURITY)
                            .content("Content")
                            .cwe("79")
                            .description("Ruleset description")
                            .executionMode(AiCustomRuleRevisionExecutionMode.AUTO)
                            .globs(Collections.singletonList("**/*.py"))
                            .isPublished(false)
                            .isTesting(false)
                            .severity(CustomRuleRevisionAttributesSeverity.ERROR)
                            .shortDescription("Ruleset short description")
                            .versionId(1L))
                    .id("revision-abc-123")
                    .type(AiCustomRuleRevisionDataType.AI_RULE_REVISION));

    try {
      apiInstance.createAiCustomRuleRevision("my-ai-ruleset", "my-ai-rule", body);
    } catch (ApiException e) {
      System.err.println("Exception when calling StaticAnalysisApi#createAiCustomRuleRevision");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"
```
{% /tab %}

{% tab label="Python" %}
```python
"""
Create an AI custom rule revision returns "Successfully created" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.static_analysis_api import StaticAnalysisApi
from datadog_api_client.v2.model.ai_custom_rule_revision_data_type import AiCustomRuleRevisionDataType
from datadog_api_client.v2.model.ai_custom_rule_revision_execution_mode import AiCustomRuleRevisionExecutionMode
from datadog_api_client.v2.model.ai_custom_rule_revision_request import AiCustomRuleRevisionRequest
from datadog_api_client.v2.model.ai_custom_rule_revision_request_attributes import AiCustomRuleRevisionRequestAttributes
from datadog_api_client.v2.model.ai_custom_rule_revision_request_data import AiCustomRuleRevisionRequestData
from datadog_api_client.v2.model.custom_rule_revision_attributes_category import CustomRuleRevisionAttributesCategory
from datadog_api_client.v2.model.custom_rule_revision_attributes_severity import CustomRuleRevisionAttributesSeverity

body = AiCustomRuleRevisionRequest(
    data=AiCustomRuleRevisionRequestData(
        attributes=AiCustomRuleRevisionRequestAttributes(
            category=CustomRuleRevisionAttributesCategory.SECURITY,
            content="Content",
            cwe="79",
            description="Ruleset description",
            directories=[],
            execution_mode=AiCustomRuleRevisionExecutionMode.AUTO,
            globs=[
                "**/*.py",
            ],
            is_published=False,
            is_testing=False,
            severity=CustomRuleRevisionAttributesSeverity.ERROR,
            short_description="Ruleset short description",
            version_id=1,
        ),
        id="revision-abc-123",
        type=AiCustomRuleRevisionDataType.AI_RULE_REVISION,
    ),
)

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
configuration.unstable_operations["create_ai_custom_rule_revision"] = True
with ApiClient(configuration) as api_client:
    api_instance = StaticAnalysisApi(api_client)
    api_instance.create_ai_custom_rule_revision(ruleset_name="my-ai-ruleset", rule_name="my-ai-rule", body=body)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"
```
{% /tab %}

{% tab label="Ruby" %}
```ruby
# Create an AI custom rule revision returns "Successfully created" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.access_token = ENV["DD_BEARER_TOKEN"]
  config.unstable_operations["v2.create_ai_custom_rule_revision".to_sym] = true
end
api_instance = DatadogAPIClient::V2::StaticAnalysisAPI.new

body = DatadogAPIClient::V2::AiCustomRuleRevisionRequest.new({
  data: DatadogAPIClient::V2::AiCustomRuleRevisionRequestData.new({
    attributes: DatadogAPIClient::V2::AiCustomRuleRevisionRequestAttributes.new({
      category: DatadogAPIClient::V2::CustomRuleRevisionAttributesCategory::SECURITY,
      content: "Content",
      cwe: "79",
      description: "Ruleset description",
      directories: [],
      execution_mode: DatadogAPIClient::V2::AiCustomRuleRevisionExecutionMode::AUTO,
      globs: [
        "**/*.py",
      ],
      is_published: false,
      is_testing: false,
      severity: DatadogAPIClient::V2::CustomRuleRevisionAttributesSeverity::ERROR,
      short_description: "Ruleset short description",
      version_id: 1,
    }),
    id: "revision-abc-123",
    type: DatadogAPIClient::V2::AiCustomRuleRevisionDataType::AI_RULE_REVISION,
  }),
})
p api_instance.create_ai_custom_rule_revision("my-ai-ruleset", "my-ai-rule", body)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"
```
{% /tab %}

{% tab label="Rust" %}
```rust
// Create an AI custom rule revision returns "Successfully created" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_static_analysis::StaticAnalysisAPI;
use datadog_api_client::datadogV2::model::AiCustomRuleRevisionDataType;
use datadog_api_client::datadogV2::model::AiCustomRuleRevisionExecutionMode;
use datadog_api_client::datadogV2::model::AiCustomRuleRevisionRequest;
use datadog_api_client::datadogV2::model::AiCustomRuleRevisionRequestAttributes;
use datadog_api_client::datadogV2::model::AiCustomRuleRevisionRequestData;
use datadog_api_client::datadogV2::model::CustomRuleRevisionAttributesCategory;
use datadog_api_client::datadogV2::model::CustomRuleRevisionAttributesSeverity;

#[tokio::main]
async fn main() {
    let body = AiCustomRuleRevisionRequest::new().data(
        AiCustomRuleRevisionRequestData::new()
            .attributes(
                AiCustomRuleRevisionRequestAttributes::new(
                    CustomRuleRevisionAttributesCategory::SECURITY,
                    "Content".to_string(),
                    "Ruleset description".to_string(),
                    vec![],
                    AiCustomRuleRevisionExecutionMode::AUTO,
                    vec!["**/*.py".to_string()],
                    false,
                    false,
                    CustomRuleRevisionAttributesSeverity::ERROR,
                    "Ruleset short description".to_string(),
                )
                .cwe(Some("79".to_string()))
                .version_id(1),
            )
            .id("revision-abc-123".to_string())
            .type_(AiCustomRuleRevisionDataType::AI_RULE_REVISION),
    );
    let mut configuration = datadog::Configuration::new();
    configuration.set_unstable_operation_enabled("v2.create_ai_custom_rule_revision", true);
    let api = StaticAnalysisAPI::with_config(configuration);
    let resp = api
        .create_ai_custom_rule_revision("my-ai-ruleset".to_string(), "my-ai-rule".to_string(), body)
        .await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run
```
{% /tab %}

{% tab label="TypeScript" %}
```typescript
/**
 * Create an AI custom rule revision returns "Successfully created" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration({
  authMethods: {
    AuthZ: {
      accessToken: process.env.DD_BEARER_TOKEN as string,
    },
  },
});
configuration.unstableOperations["v2.createAiCustomRuleRevision"] = true;
const apiInstance = new v2.StaticAnalysisApi(configuration);

const params: v2.StaticAnalysisApiCreateAiCustomRuleRevisionRequest = {
  body: {
    data: {
      attributes: {
        category: "SECURITY",
        content: "Content",
        cwe: "79",
        description: "Ruleset description",
        directories: [],
        executionMode: "auto",
        globs: ["**/*.py"],
        isPublished: false,
        isTesting: false,
        severity: "ERROR",
        shortDescription: "Ruleset short description",
        versionId: 1,
      },
      id: "revision-abc-123",
      type: "ai_rule_revision",
    },
  },
  rulesetName: "my-ai-ruleset",
  ruleName: "my-ai-rule",
};

apiInstance
  .createAiCustomRuleRevision(params)
  .then((data: any) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"
```
{% /tab %}
{% /tabs %}
