Text Moderation

Analyze text for potential moderation issues.

POSThttps://api.safecomms.dev/moderation/text

The text moderation endpoint analyzes a string of text for various types of unsafe content, including hate speech, harassment, self-harm, sexual content, and violence. It can also detect Personally Identifiable Information (PII) and automatically redact sensitive or offensive content.

Request Parameters

ParameterTypeDescription
contentstringThe text content to analyze. Maximum length depends on your subscription tier.
languagestring ISO 639-1 language code (e.g., 'en', 'es').
Note: Set to 'auto' for automatic language detection (Business and Enterprise tiers only).
replacebooleanIf true, returns moderatedContent with flagged terms replaced by asterisks. Default: false.
piibooleanIf true, scans for Personally Identifiable Information (emails, phone numbers, etc.). Default: false.
replaceSeveritystringMinimum severity level to trigger replacement. Options: 'Low', 'Medium', 'High'.
moderationProfileIdstringThe ID of a custom moderation profile to apply specific rules.

Token Usage & Costs

Text moderation uses a base cost of 1 token per request. Additional features (add-ons) may incur extra token costs.

FeatureCostTierCondition
Base Request1 TokenFree+Always applied.
Non-English Language+1Pro+ Applied when language is not 'en'.
If set to 'auto' and resolves to English, no surcharge is applied.
Text Replacement+1Starter+Applied when replace is set to true.
PII Detection+1Starter+Applied when pii is set to true.

* Note: You must have enough tokens in your balance to cover the maximum potential cost of the request (Base + all enabled add-ons) to initiate the call.

Example Request

{
  "content": "This is some text to check.",
  "language": "en",
  "replace": true,
  "pii": false
}

Response Object

The API returns a JSON object containing the analysis results.

  • isClean: Boolean indicating if the content passed all checks.
  • flaggedCategories: List of categories that triggered a flag.
  • moderatedContent: The content with offensive parts redacted (if replacement was enabled).
{
  "isClean": false,
  "flaggedCategories": [
    {
      "category": "Hate Speech",
      "severity": "High",
      "confidence": 0.98
    }
  ],
  "originalContent": "This is some text to check.",
  "moderatedContent": "This is some **** to check.",
  "requestId": "req_123456789"
}