Submit content for moderation and receive detailed analysis
Moderate text and image content for inappropriate or harmful material
The endpoint accepts a JSON payload with an array of input items. Each item must have a type
field indicating whether it's text
or image
.
Parameter | Type | Description | Required |
---|---|---|---|
input | array | Array of content items to moderate | Yes |
analyze_images | boolean | Whether to perform deep analysis on images using vision models | No (default: false) |
Each item in the input array must have the following format:
{
"type": "text",
"text": "The text content to moderate"
}
{
"type": "image",
"base64": "data:image/jpeg;base64,/9j/4AAQSkZ..."
}
The base64
field must contain a valid base64-encoded image with the appropriate MIME type prefix (e.g., data:image/jpeg;base64,
).
{
"input": [
{ "type": "text", "text": "This restaurant has amazing food!" },
{ "type": "text", "text": "The service was excellent and I highly recommend the steak." },
{ "type": "image", "base64": "data:image/jpeg;base64,/9j/4AAQSkZ..." },
{ "type": "image", "base64": "data:image/jpeg;base64,iVBORw0KGg..." }
],
"analyze_images": true
}
The response includes moderation results for each input item, as well as a combined result for all text items. If analyze_images
is set to true
, the response also includes vision analysis for each image.
Field | Type | Description |
---|---|---|
id | string | Unique identifier for the moderation request |
model | string | The moderation model used for the request |
results | array | Array of moderation results for each input item |
combined_text_moderation | object | Moderation result for all text items combined (only relevant when multiple text items are present) |
vision_analysis | array | Array of vision analysis results for each image (only present if analyze_images is true) |
flagged | boolean | Whether any content was flagged as inappropriate |
signature | string | Cryptographic signature for verifying the response |
{
"id": "modr-123456",
"model": "text-moderation-latest",
"results": [
{
"flagged": false,
"categories": {
"hate": false,
"harassment": false,
"self-harm": false,
"sexual": false,
"violence": false
},
"category_scores": {
"hate": 0.0,
"harassment": 0.0,
"self-harm": 0.0,
"sexual": 0.0,
"violence": 0.0
}
},
{
"flagged": false,
"categories": {
"hate": false,
"harassment": false,
"self-harm": false,
"sexual": false,
"violence": false
},
"category_scores": {
"hate": 0.0,
"harassment": 0.0,
"self-harm": 0.0,
"sexual": 0.0,
"violence": 0.0
}
},
{
"flagged": false,
"categories": {
"hate": false,
"harassment": false,
"self-harm": false,
"sexual": false,
"violence": false
},
"category_scores": {
"hate": 0.0,
"harassment": 0.0,
"self-harm": 0.0,
"sexual": 0.0,
"violence": 0.0
}
},
{
"flagged": false,
"categories": {
"hate": false,
"harassment": false,
"self-harm": false,
"sexual": false,
"violence": false
},
"category_scores": {
"hate": 0.0,
"harassment": 0.0,
"self-harm": 0.0,
"sexual": 0.0,
"violence": 0.0
}
}
],
"combined_text_moderation": {
"flagged": false,
"categories": {
"hate": false,
"harassment": false,
"self-harm": false,
"sexual": false,
"violence": false
},
"category_scores": {
"hate": 0.0,
"harassment": 0.0,
"self-harm": 0.0,
"sexual": 0.0,
"violence": 0.0
}
},
"vision_analysis": [
{
"image_index": 2,
"analysis": "This image shows a plate of beautifully presented food in what appears to be a restaurant setting. The dish looks like a well-plated steak with garnishes and side dishes. The lighting is good, the food appears appetizing, and the image is of high quality. This is perfectly appropriate for a restaurant listing or review as it showcases the food offerings. VERDICT: APPROPRIATE",
"flagged": false
},
{
"image_index": 3,
"analysis": "This image shows the interior of a restaurant with tables and chairs. The space appears clean, well-lit, and professionally designed. This is an appropriate image for a restaurant listing as it accurately represents the dining environment for potential customers. There are no inappropriate elements or overlays in the image. VERDICT: APPROPRIATE",
"flagged": false
}
],
"flagged": false,
"signature": "abcdef1234567890"
}
The API returns appropriate HTTP status codes for different error scenarios:
Status Code | Description |
---|---|
400 Bad Request | Invalid request format or content |
401 Unauthorized | Missing API key |
403 Forbidden | Invalid API key or insufficient permissions |
429 Too Many Requests | Rate limit exceeded |
500 Internal Server Error | Server-side error |
Error responses have a consistent format:
{
"error": {
"code": "error_code",
"message": "Detailed error message"
}
}
async function moderateContent(apiKey, textContent, imageBase64) {
const response = await fetch('https://api.omnimoderate.com/v1/moderate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': apiKey
},
body: JSON.stringify({
input: [
{ type: 'text', text: textContent },
{ type: 'image', base64: imageBase64 }
],
analyze_images: true
})
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error.message || 'Moderation request failed');
}
return await response.json();
}
import requests
import json
def moderate_content(api_key, text_content, image_base64):
url = "https://api.omnimoderate.com/v1/moderate"
headers = {
"Content-Type": "application/json",
"X-API-Key": api_key
}
payload = {
"input": [
{"type": "text", "text": text_content},
{"type": "image", "base64": image_base64}
],
"analyze_images": True
}
response = requests.post(url, headers=headers, json=payload)
if response.status_code != 200:
error_data = response.json()
raise Exception(error_data.get("error", {}).get("message", "Moderation request failed"))
return response.json()