Text Moderation
Analyze text for potential moderation issues.
POST
https://api.safecomms.dev/moderation/textThe 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
| Parameter | Type | Description |
|---|---|---|
| content | string | The text content to analyze. Maximum length depends on your subscription tier. |
| language | string | ISO 639-1 language code (e.g., 'en', 'es'). Note: Set to 'auto' for automatic language detection (Business and Enterprise tiers only). |
| replace | boolean | If true, returns moderatedContent with flagged terms replaced by asterisks. Default: false. |
| pii | boolean | If true, scans for Personally Identifiable Information (emails, phone numbers, etc.). Default: false. |
| replaceSeverity | string | Minimum severity level to trigger replacement. Options: 'Low', 'Medium', 'High'. |
| moderationProfileId | string | The 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.
| Feature | Cost | Tier | Condition |
|---|---|---|---|
| Base Request | 1 Token | Free+ | Always applied. |
| Non-English Language | +1 | Pro+ | Applied when language is not 'en'. If set to 'auto' and resolves to English, no surcharge is applied. |
| Text Replacement | +1 | Starter+ | Applied when replace is set to true. |
| PII Detection | +1 | Starter+ | 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"
}