> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://fastpix.com/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://fastpix.com/docs/_mcp/server.

# Create a moderation rule

POST https://api.fastpix.com/v1/agents/moderation/rules
Content-Type: application/json

This endpoint creates a moderation rule. A rule defines a named set of category conditions that determine what the moderation agent flags and which action it applies (cut, blur, beep, mute, or flag).

Each condition targets a detection category on an audio or video track. You can optionally specify a confidence threshold between 0 and 1. If you omit the threshold, the system uses the default value for that category.

#### How it works

1. Send a POST request with a `name` and a non-empty `conditions` array.

2. For each condition, specify a `category`, a `type` (`audio` or `video`), and optionally a `threshold` and an `action`.

3. The response returns the ID of the created rule. Use this ID as `ruleId` when creating a moderation job.

A rule name must be unique. Each category can appear only once in a rule.

#### Example

A video platform creates a rule that flags nudity and graphic violence on the video track and mutes profanity on the audio track, then reuses it across every upload job.


Reference: https://fastpix.com/docs/agents-api/moderation-agent/create-moderation-rule

## Authentication

- `Authorization` header (basic auth, required) — FastPix APIs are secured with Basic Authentication. Use your Access Token ID as the username and Secret Key as the password in the Authorization header of each API request. * Username: Access Token ID * Password: Secret Key Activate your FastPix account to generate your API credentials. See the guide here

## Request

### Body (application/json)

This endpoint expects a CreateModerationRuleRequest.

- `name` (string, required) — A human-readable name for the rule. Must be unique within the workspace.
- `conditions` (list of ModerationConditionInput, required) — One or more category conditions. A category can appear only once per rule.

## Response

### 200

Moderation rule created successfully

- `success` (boolean, optional) — Shows the request status. Returns true for success and false for failure.
- `data` (ModerationResourceCreatedResponseData, optional)

## Types

### ModerationConditionInput

One category condition submitted when creating a rule.

- `category` (enum, required) — The moderation detection category a condition targets.
  - Allowed values: `profanity`, `harassment`, `threats`, `violence`, `violence_graphic`, `nudity`, `minors_present`, `drugs_alcohol`, `smoking_tobacco`, `sexual_minors`, `child_abuse`, `religious_sensitive`, `religious_desecration`
- `type` (enum, required) — The media track a condition is evaluated on.
  - Allowed values: `audio`, `video`
- `threshold` (double, optional, nullable) — Confidence threshold between 0 and 1. Omit (or send null) to inherit the system default for the category.
- `action` (enum, optional, nullable) — Action to apply when the condition matches. Omit to inherit the default action for the category.
  - Allowed values: `cut`, `blur`, `flag`, `beep`, `mute`

### ModerationResourceCreatedResponseData

- `id` (string, optional) — The unique identifier of the created resource.

## Examples

**Request**

```json
{
  "name": "Strict UGC policy",
  "conditions": [
    {
      "category": "nudity",
      "type": "video"
    }
  ]
}
```

**Response**

```json
{
  "success": true,
  "data": {
    "id": "3c7fae25-8b40-4f69-9d13-2a0b7c4e6f33"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.fastpix.com/v1/agents/moderation/rules"

payload = {
    "name": "Strict UGC policy",
    "conditions": [
        {
            "category": "nudity",
            "type": "video"
        }
    ]
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<username>", "<password>"))

print(response.json())
```

```javascript
const url = 'https://api.fastpix.com/v1/agents/moderation/rules';
const credentials = btoa("<username>:<password>");

const options = {
  method: 'POST',
  headers: {
    Authorization: `Basic ${credentials}`,
    'Content-Type': 'application/json'
  },
  body: '{"name":"Strict UGC policy","conditions":[{"category":"nudity","type":"video"}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.fastpix.com/v1/agents/moderation/rules"

	payload := strings.NewReader("{\n  \"name\": \"Strict UGC policy\",\n  \"conditions\": [\n    {\n      \"category\": \"nudity\",\n      \"type\": \"video\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<username>", "<password>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.fastpix.com/v1/agents/moderation/rules")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<username>", "<password>")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Strict UGC policy\",\n  \"conditions\": [\n    {\n      \"category\": \"nudity\",\n      \"type\": \"video\"\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.fastpix.com/v1/agents/moderation/rules")
  .basicAuth("<username>", "<password>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Strict UGC policy\",\n  \"conditions\": [\n    {\n      \"category\": \"nudity\",\n      \"type\": \"video\"\n    }\n  ]\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.fastpix.com/v1/agents/moderation/rules', [
  'body' => '{
  "name": "Strict UGC policy",
  "conditions": [
    {
      "category": "nudity",
      "type": "video"
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<username>', '<password>'],
]);

echo $response->getBody();
```

```csharp
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.fastpix.com/v1/agents/moderation/rules");
client.Authenticator = new HttpBasicAuthenticator("<username>", "<password>");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Strict UGC policy\",\n  \"conditions\": [\n    {\n      \"category\": \"nudity\",\n      \"type\": \"video\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let credentials = Data("<username>:<password>".utf8).base64EncodedString()

let headers = [
  "Authorization": "Basic \(credentials)",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Strict UGC policy",
  "conditions": [
    [
      "category": "nudity",
      "type": "video"
    ]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.fastpix.com/v1/agents/moderation/rules")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```