← Back to Home

CleanMod API Documentation

Authentication

All API requests require authentication using an API key. You can obtain an API key from your dashboard.

Include your API key in requests using one of the following methods:

Recommended: Authorization Header

Authorization: Bearer <API_KEY>

Alternative: Custom Header

x-api-key: <API_KEY>

⚠️ Security Warning

API keys are secret credentials. Never expose them in client-side JavaScript, public repositories, or client-side code. Always use server-side code or environment variables to store and use API keys.

Moderate Text

Analyze text content for toxicity, insults, threats, and other harmful content.

Endpoint

POST https://cleanmod.dev/api/v1/moderate

Content-Type

application/json

Request Body

{
  "text": "You are an idiot",
  "model": "english-basic",
  "mode": "strict"
}

text (required): The text content to moderate. Must be a non-empty string.

model (optional): The moderation model to use. Defaults to english-basic.

mode (optional): The moderation sensitivity mode. Controls the thresholds used for flagging and blocking content. Must be one of: lenient, default, or strict. If not provided, uses your organization's default mode (set in dashboard), or falls back to default.

Mode Thresholds:

  • lenient: flag: 0.9, block: 0.98 (only very toxic content is flagged)
  • default: flag: 0.8, block: 0.95 (balanced moderation)
  • strict: flag: 0.3, block: 0.6 (more aggressive flagging)

Response Body

{
  "id": "log_abc123...",
  "model": "english-basic",
  "provider": "unitary",
  "providerModel": "unitary/multilingual-toxic-xlm-roberta",
  "decision": "flag",
  "overall_score": 0.91,
  "mode": "strict",
  "thresholds": {
    "flag": 0.3,
    "block": 0.6
  },
  "categories": {
    "toxicity": 0.91,
    "insult": 0.88
  },
  "created_at": "2025-11-16T15:00:00.000Z"
}

id: Unique identifier for this moderation log entry.

decision: One of allow, flag, or block.

overall_score: Overall toxicity score (0-1), where higher values indicate more toxic content.

mode: The moderation mode that was used for this request (either from the request body or your organization's default).

thresholds: The flag and block thresholds that were used for this request, based on the mode.

categories: Per-category scores for different types of harmful content.

WordPress Integration

CleanMod has an official WordPress plugin for moderating comments. It uses the same API as the examples above, just wrapped in a plugin UX for easy WordPress integration. Perfect for blogs, WooCommerce stores, and content-heavy sites.

Installation

  1. In your WordPress admin, go to Plugins → Add New.
  2. Search for "CleanMod – AI Comment Moderation" or directly install from wordpress.org/plugins/cleanmod/.
  3. Click Install, then Activate.
  4. After activation, go to Settings → CleanMod.

Note: If the plugin is not searchable yet, you can manually download it from the WordPress.org plugin page and upload as a ZIP under "Plugins → Add New → Upload Plugin".

Get an API Key

  1. From cleanmod.dev, sign in (Clerk).
  2. Go to Dashboard → API Keys.
  3. Click Create API Key, copy the value.
  4. Paste this into the API Key field in the CleanMod settings page in WordPress.

Behavior Configuration

The plugin lets you configure how to handle different moderation decisions:

For decision = "flag":

  • No change (pass-through): Comment proceeds normally, respecting WordPress default settings.
  • Hold for moderation: Comment is held for manual review (recommended).

Flag decisions indicate "suspicious but not necessarily terrible" content—recommended: hold for manual review.

For decision = "block":

  • Hold for moderation: Comment is held for manual review.
  • Mark as spam: Comment is automatically marked as spam (recommended).

Block decisions indicate "likely very toxic" content—recommended: mark as spam or hold.

How Moderation Works (Under the Hood)

The plugin hooks into WordPress's pre_comment_approved filter:

  • When a new comment is submitted on the front-end, the plugin sends the comment text to https://cleanmod.dev/api/v1/moderate with your configured API key.
  • If the API returns an error, the plugin fails open (does not block the comment) to ensure comment submission isn't broken.
  • If CleanMod returns allow, flag, or block, the plugin applies your chosen behavior setting.
  • Admin bulk actions and backend edits are not re-moderated—only new front-end submissions trigger moderation.

Privacy Note: If the API fails, the plugin fails open (doesn't break comment submission). Comments are sent as text only—no user identities are shared with CleanMod.

JavaScript SDK

CleanMod provides an official JavaScript/TypeScript SDK for easy integration in Node.js, serverless functions, and backend frameworks.

Installation

npm install @cleanmod/js

# or

yarn add @cleanmod/js

# or

pnpm add @cleanmod/js

Quick Example

import { createCleanModClient } from "@cleanmod/js";

const client = createCleanModClient({
  apiKey: process.env.CLEANMOD_API_KEY!,
});

const res = await client.moderate({
  text: "you are an idiot"
});

console.log(res);

The SDK uses the same moderation engine as the REST API and supports all models and future features.

Error Responses

The API returns standard HTTP status codes and JSON error responses.

400 Bad Request

Invalid or missing request body fields.

{
  "error": "Missing or invalid \"text\" field in request body."
}
400 Bad Request

Invalid mode value.

{
  "error": "Invalid \"mode\" value. Must be one of: \"lenient\", \"default\", \"strict\"."
}
401 Unauthorized

Missing or invalid API key.

{
  "error": "Missing API key. Use Authorization: Bearer <KEY> or x-api-key."
}
429 Too Many Requests

Monthly quota exceeded.

{
  "error": "Monthly quota exceeded. Upgrade your CleanMod plan to continue.",
  "quota": 2000,
  "used": 2000
}
500 Internal Server Error

An unexpected error occurred on the server.

{
  "error": "Internal server error."
}

Code Examples

JavaScript SDK (@cleanmod/js)

import { CleanModClient } from "@cleanmod/js";

const client = new CleanModClient({
  apiKey: process.env.CLEANMOD_API_KEY!,
  // baseUrl is optional, defaults to https://cleanmod.dev
  baseUrl: "https://cleanmod.dev",
});

async function run() {
  const result = await client.moderate({
    text: "You are an idiot",
    model: "english-basic",
  });

  console.log(result.decision, result.overallScore);
}

run().catch(console.error);

cURL

curl -X POST https://cleanmod.dev/api/v1/moderate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "You are an idiot",
    "model": "english-basic",
    "mode": "strict"
  }'

Node.js (fetch)

const response = await fetch('https://cleanmod.dev/api/v1/moderate', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    text: 'You are an idiot',
    model: 'english-basic',
  }),
});

const result = await response.json();
console.log(result);

Python (requests)

import requests

response = requests.post(
    'https://cleanmod.dev/api/v1/moderate',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json',
    },
    json={
        'text': 'You are an idiot',
        'model': 'english-basic',
    },
)

result = response.json()
print(result)

PHP

<?php

$url = 'https://cleanmod.dev/api/v1/moderate';
$data = [
    'text' => 'You are an idiot',
    'model' => 'english-basic',
];

$options = [
    'http' => [
        'method' => 'POST',
        'header' => [
            'Authorization: Bearer YOUR_API_KEY',
            'Content-Type: application/json',
        ],
        'content' => json_encode($data),
    ],
];

$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$result = json_decode($response, true);

var_dump($result);

Open Source & SDKs

CleanMod provides official SDKs and integrations to make integration easier. All SDKs and plugins are open source.

JavaScript SDK – @cleanmod/js

Use this in Node.js / Next.js / serverless functions instead of hand-rolling fetch calls to /api/v1/moderate.

WordPress Plugin – CleanMod – AI Comment Moderation

Automatically moderate WordPress comments using CleanMod. Install it directly from your WP admin or download from WordPress.org.