Moderate Content Endpoint

Submit content for moderation and receive detailed analysis

POST/moderate

Moderate text and image content for inappropriate or harmful material

Request Format

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.

Request Parameters

ParameterTypeDescriptionRequired
inputarrayArray of content items to moderateYes
analyze_imagesbooleanWhether to perform deep analysis on images using vision modelsNo (default: false)

Input Item Format

Each item in the input array must have the following format:

Text Item

{
  "type": "text",
  "text": "The text content to moderate"
}

Image Item

{
  "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,).

Example Request

request.json
{
  "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
}

Response Format

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.

Response Fields

FieldTypeDescription
idstringUnique identifier for the moderation request
modelstringThe moderation model used for the request
resultsarrayArray of moderation results for each input item
combined_text_moderationobjectModeration result for all text items combined (only relevant when multiple text items are present)
vision_analysisarrayArray of vision analysis results for each image (only present if analyze_images is true)
flaggedbooleanWhether any content was flagged as inappropriate
signaturestringCryptographic signature for verifying the response

Example Response

response.json
{
  "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"
}

Error Responses

The API returns appropriate HTTP status codes for different error scenarios:

Status CodeDescription
400 Bad RequestInvalid request format or content
401 UnauthorizedMissing API key
403 ForbiddenInvalid API key or insufficient permissions
429 Too Many RequestsRate limit exceeded
500 Internal Server ErrorServer-side error

Error responses have a consistent format:

{
  "error": {
    "code": "error_code",
    "message": "Detailed error message"
  }
}

Code Examples

JavaScript

moderate-content.js
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();
}

Python

moderate_content.py
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()

Next Steps