API Documentation

Everything you need to integrate moder8r into your application

Perspective API - Analyze

Drop-in replacement for Google's Perspective API. Use the same request format to analyze text for toxicity, profanity, threats, and more.

Google Perspective API compatible. Existing Perspective API integrations work with moder8r by changing only the base URL. The same moder8r API keys (m8r_sk_...) are used for authentication.

POST
/v1alpha1/comments:analyze

Analyze Comment

Analyze text for harmful attributes using the Google Perspective API request format. Accessible via subdomain (perspective.moder8r.app) or path (/api/perspective/v1alpha1/comments:analyze).

Parameters

NameTypeRequiredDescription
commentobject
Required
Object with a "text" field (required, 1 to 3,000 characters) and an optional "type" field ("PLAIN_TEXT" or "HTML"). "type" is accepted for compatibility, but text is always analyzed as-is (HTML is not stripped).
Example: { "text": "Hello world", "type": "PLAIN_TEXT" }
requestedAttributesobject
Required
Map of attribute names to configuration objects. At least one attribute is required; unknown names return 400 INVALID_ARGUMENT. scoreThreshold (0 to 1) omits that attribute from the response when its score is below the threshold. scoreType is accepted but ignored: scores are always PROBABILITY.
Example: { "TOXICITY": {}, "INSULT": { "scoreThreshold": 0.8 } }
languagesstring[]
Optional
ISO 639-1 language codes. Echoed back as both languages and detectedLanguages; not used for scoring (the model handles multilingual input natively).
Example: ["en"]
doNotStoreboolean
Optional
If true, moder8r doesn't write this request to its request log. Defaults to false. The request still counts toward your quota.
Example: true
clientTokenstring
Optional
An opaque token echoed back in the response for client-side correlation.
Example: "my-request-123"
communityIdstring
Optional
Accepted for compatibility; not used by analyze. (It is stored when sent to suggestscore.)
Example: "my-forum"
context / sessionIdobject / string
Optional
Accepted for compatibility with Perspective clients; currently ignored.
spanAnnotationsboolean
Optional
If true, each attribute includes spanScores: up to 5 approximate character ranges that most exhibit the attribute. Attributes scoring 0.3 or lower get a single span covering the whole text. Adds latency.
Example: true

Base URLs

MethodURL
Subdomain (recommended)https://perspective.moder8r.app/v1alpha1/comments:analyze
Path-basedhttps://moder8r.app/api/perspective/v1alpha1/comments:analyze

Authentication

MethodExampleNotes
Query parameter?key=m8r_sk_...Google-compatible method
Bearer tokenAuthorization: Bearer m8r_sk_...
Recommended

Request

cURL Request
curl -X POST 'https://perspective.moder8r.app/v1alpha1/comments:analyze?key=m8r_sk_your_key_here' \
  -H "Content-Type: application/json" \
  -d '{
    "comment": { "text": "You are an idiot and nobody likes you." },
    "requestedAttributes": {
      "TOXICITY": {},
      "PROFANITY": {},
      "INSULT": {}
    },
    "languages": ["en"]
  }'

Response

Success Response
{
  "attributeScores": {
    "TOXICITY": {
      "summaryScore": { "value": 0.9134567201, "type": "PROBABILITY" }
    },
    "PROFANITY": {
      "summaryScore": { "value": 0.05, "type": "PROBABILITY" }
    },
    "INSULT": {
      "summaryScore": { "value": 0.9134567201, "type": "PROBABILITY" }
    }
  },
  "languages": ["en"],
  "detectedLanguages": ["en"]
}

Supported Attributes

All attributes also support an _EXPERIMENTAL suffix (e.g., TOXICITY_EXPERIMENTAL) which returns the same score.

AttributeDescription
TOXICITYRude, disrespectful, or unreasonable comment likely to make people leave a discussion
SEVERE_TOXICITYVery hateful, aggressive, or disrespectful comment very likely to make people leave
IDENTITY_ATTACKNegative or hateful comment targeting someone because of their identity
INSULTInsulting, inflammatory, or negative comment towards a person or group
PROFANITYSwear words, curse words, or other obscene or profane language
THREATDescribes an intention to inflict pain, injury, or violence against a person or group
SEXUALLY_EXPLICITContains references to sexual acts, body parts, or other lewd content
FLIRTATIONPickup lines, complimenting appearance, subtle sexual innuendos
SPAMIrrelevant, promotional, or nonsensical content
OBSCENEOffensive or disgusting language or imagery
ATTACK_ON_COMMENTERAttack directed at another commenter in the discussion
ATTACK_ON_AUTHORAttack directed at the author of the original content
INCOHERENTDifficult to understand or nonsensical
INFLAMMATORYIntended to provoke or inflame
LIKELY_TO_REJECTLikely to be rejected by a human moderator
UNSUBSTANTIALTrivial or short comment that lacks substance

Response Fields

attributeScores

Map of requested attribute names to their score objects. Each contains a summaryScore with value (0.0 to 1.0) and type ("PROBABILITY").

attributeScores.*.spanScores

Only present when spanAnnotations: true. Array of per-span scores with begin and end character offsets and a score object.

languages

Echoed from the request if provided; omitted otherwise. detectedLanguages is set to the same value (no language detection is performed).

clientToken

Echoed from the request if provided. Useful for correlating requests and responses.

Quota, Rate Limits & Errors

  • Each successful analyze call uses one request from the same monthly quota as the native API, however many attributes you request.
  • It shares the same per-minute window as the native API for that key. Successful responses include X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset (Unix milliseconds).
  • Errors use Google's error shape (error.code, error.message, error.status, error.errors[]).
Statuserror.statuserrors[0].reasonWhen
400INVALID_ARGUMENTinvalidBad JSON, missing/empty comment.text, text over 3,000 characters, unknown attribute, bad scoreThreshold, or wrong type for languages/doNotStore/spanAnnotations
401UNAUTHENTICATEDunauthorizedMissing, unknown, or revoked key
429RESOURCE_EXHAUSTEDrateLimitExceededPer-minute rate limit reached (no Retry-After header)
429RESOURCE_EXHAUSTEDquotaExceededMonthly quota used up
503UNAVAILABLEbackendErrorUpstream moderation service unavailable
500INTERNALinternalErrorUnexpected server error

Code Examples

JavaScript / Node.js

// JavaScript / Node.js
const response = await fetch(
  'https://perspective.moder8r.app/v1alpha1/comments:analyze',
  {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer m8r_sk_your_key_here',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      comment: { text: 'Is this comment toxic?' },
      requestedAttributes: {
        TOXICITY: {},
        SEVERE_TOXICITY: {},
        PROFANITY: {},
      },
    }),
  }
);

const data = await response.json();
console.log(data.attributeScores.TOXICITY.summaryScore.value);

Python

# Python
import requests

url = 'https://perspective.moder8r.app/v1alpha1/comments:analyze'
headers = {
    'Authorization': 'Bearer m8r_sk_your_key_here',
    'Content-Type': 'application/json',
}
data = {
    'comment': { 'text': 'Is this comment toxic?' },
    'requestedAttributes': {
        'TOXICITY': {},
        'SEVERE_TOXICITY': {},
        'PROFANITY': {},
    },
}

response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result['attributeScores']['TOXICITY']['summaryScore']['value'])

Span Annotations

// Request with span annotations
const response = await fetch(
  'https://perspective.moder8r.app/v1alpha1/comments:analyze',
  {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer m8r_sk_your_key_here',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      comment: { text: 'You are terrible. Have a nice day.' },
      requestedAttributes: { TOXICITY: {} },
      spanAnnotations: true,
    }),
  }
);

// Response includes spanScores:
// {
//   "attributeScores": {
//     "TOXICITY": {
//       "summaryScore": { "value": 0.65, "type": "PROBABILITY" },
//       "spanScores": [
//         { "begin": 0, "end": 18, "score": { "value": 0.92, "type": "PROBABILITY" } },
//         { "begin": 19, "end": 35, "score": { "value": 0.05, "type": "PROBABILITY" } }
//       ]
//     }
//   }
// }

Migration from Google Perspective API

Minimal changes required. Replace Google's base URL with https://perspective.moder8r.app and swap your Google API key for a moder8r API key. The request and response format is identical.

DetailGoogle Perspectivemoder8r
Base URLcommentanalyzer.googleapis.comperspective.moder8r.app
Auth?key=AIza...?key=m8r_sk_... or Bearer token
Max text length20,480 bytes3,000 characters
Attributes6 production + 10 experimentalAll 16 supported (production and experimental return the same score)
Rate limitsQPS-basedPer-minute sliding window (same as native API)
Score typesPROBABILITYPROBABILITY only (scoreType ignored)
Error formatGoogle API errorsGoogle API errors (same shape)