Moderation / Text moderation
Moderation

Text moderation

Moderate text with the Detectivision API: check messages, comments and posts for your account's flags, each with its confidence.

On this page

Send the text itself as input, in a JSON body. It is checked exactly as you send it: nothing is trimmed.

Note

Text flags judge the whole text: answers have no positions, and capture and censor return what detect returns, at the same price.

curl https://api.detectivision.ai/api/v1/moderation \
  -H "Api-Key: $DETECTIVISION_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type": "text_moderation", "input": "Sen salak birisin, senden nefret ediyorum."}'
import os, requests

r = requests.post(
    "https://api.detectivision.ai/api/v1/moderation",
    headers={"Api-Key": os.environ["DETECTIVISION_API_KEY"]},
    json={"type": "text_moderation", "input": "Sen salak birisin, senden nefret ediyorum."},
)
print(r.json())
const res = await fetch("https://api.detectivision.ai/api/v1/moderation", {
  method: "POST",
  headers: { "Api-Key": process.env.DETECTIVISION_API_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({ type: "text_moderation", input: "Sen salak birisin, senden nefret ediyorum." }),
});
console.log(await res.json());

Warning

Text moderation understands English, Spanish, Portuguese, French, German, Italian, Turkish, Arabic, Russian, Hindi, Chinese and Japanese; a flag may cover only some of them. Text in other languages is checked, but the results are not reliable.

Limits#

Length 1 to 10,000 characters, counted as Unicode code points (an emoji is one). Whitespace-only text is refused.
Request body JSON, at most 14 MB: 10,000 characters fit however your JSON library escapes them (an emoji as 😀).
Price 1 credit per started 2,500 characters, in every mode: 1 to 4 credits. Twice that for an answer given at once (the default); the table is the async price. See Size.
Flags Every flag of the type by default. To check some only, name them in flags, with keys from GET /api/v1/flags: the others are not checked, and the models that feed none of yours are not run. See Choosing flags.
Metadata Any JSON object, at most 16 KB, in metadata. It comes back unchanged in the answer and in webhooks. See Metadata and actions.

Flags#

Your account's text flags are the text_moderation list of GET /api/v1/flags. They depend on your plan and can change, so they are not listed here. Each of them judges the whole text; see Positions.

The result#

An example answer to the request above:

{
  "id": 1050,
  "type": "text_moderation",
  "mode": "capture",
  "status": "completed",
  "flagged": true,
  "flags": [
    { "flag": "insult", "confidence": 0.97, "detections": [{ "label": "insult", "confidence": 0.97 }] }
  ],
  "checked": ["bad_habits", "hate", "insult", "racism", "self_harm", "sexism", "sexual"],
  "unchecked": [],
  "tookMs": 95,
  "usage": { "charged": 2, "remaining": 8 }
}
  • flags lists the flags raised, each with its confidence from 0 to 1. Here insult was raised: salak calls someone a name.
  • In capture and censor mode each flag also has detections. They hold a label and a confidence and no position, so they tell you no more than detect.

Positions in text#

Text flags judge the whole text, so answers do not have these fields. This is reference for flags with positions: a detection of a flag with positions has start and end: the span of the word, as Unicode code point indexes, start inclusive and end exclusive.

Tip

In JavaScript, index code points with Array.from(text), not text.slice, so emoji and other characters outside the Basic Multilingual Plane line up: Array.from(text).slice(start, end).join(""). In Python, text[start:end] already counts code points.

Masking words#

With "mode": "censor", the answer also has censoredText: your text with every non-space character of each flagged span replaced by *, the same length as the input. Only flags with positions are masked, and text flags judge the whole text, so censoredText comes back exactly as you sent it. See Modes and censoring.

Errors specific to text#

HTTP Body Cause
400 {"error": "invalid_input", "message": "the text is empty"} Empty or whitespace-only text.
400 {"error": "invalid_input", "message": "the text is longer than 10000 characters"} Text too long. Split it and check the parts.
400 {"error": "invalid_input", "message": "the text could not be read"} The text could not be processed.
400 {"error": "invalid_input", "message": "send the text itself, not a file"} The text came as a file in a form. Send it as input in a JSON body.

All other errors are described in Errors.