> ## Documentation Index
> Fetch the complete documentation index at: https://docs.voidai.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Moderation

> Check text for potentially harmful content

```
POST /v1/moderations
```

Classifies text to determine if it contains potentially harmful content across various categories.

## Request Body

<ParamField body="input" type="string | array" required>
  The text to classify. Can be a single string or an array of strings.
</ParamField>

<ParamField body="model" type="string" default="text-moderation-latest">
  The moderation model to use. Options: `text-moderation-latest`, `text-moderation-stable`.
</ParamField>

## Response

<ResponseField name="id" type="string">
  Unique identifier for the moderation request.
</ResponseField>

<ResponseField name="model" type="string">
  The model used for classification.
</ResponseField>

<ResponseField name="results" type="array">
  Array of moderation results for each input.

  <Expandable title="Result object">
    <ResponseField name="flagged" type="boolean">
      Whether the content was flagged as potentially harmful.
    </ResponseField>

    <ResponseField name="categories" type="object">
      Object with boolean values for each category.
    </ResponseField>

    <ResponseField name="category_scores" type="object">
      Object with confidence scores (0-1) for each category.
    </ResponseField>
  </Expandable>
</ResponseField>

## Categories

| Category                 | Description                              |
| ------------------------ | ---------------------------------------- |
| `hate`                   | Content expressing hatred toward a group |
| `hate/threatening`       | Hateful content that includes threats    |
| `harassment`             | Content that harasses an individual      |
| `harassment/threatening` | Harassment that includes threats         |
| `self-harm`              | Content promoting self-harm              |
| `self-harm/intent`       | Content expressing intent to self-harm   |
| `self-harm/instructions` | Instructions for self-harm               |
| `sexual`                 | Sexual content                           |
| `sexual/minors`          | Sexual content involving minors          |
| `violence`               | Violent content                          |
| `violence/graphic`       | Graphic violent content                  |

## Examples

### Basic Moderation

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-voidai-your_key_here",
      base_url="https://api.voidai.app/v1"
  )

  response = client.moderations.create(
      input="This is a friendly message about programming."
  )

  result = response.results[0]
  print(f"Flagged: {result.flagged}")

  if result.flagged:
      for category, flagged in result.categories.items():
          if flagged:
              score = result.category_scores[category]
              print(f"  {category}: {score:.4f}")
  ```

  ```typescript TypeScript theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    apiKey: 'sk-voidai-your_key_here',
    baseURL: 'https://api.voidai.app/v1'
  });

  const response = await client.moderations.create({
    input: 'This is a friendly message about programming.'
  });

  const result = response.results[0];
  console.log(`Flagged: ${result.flagged}`);

  if (result.flagged) {
    for (const [category, flagged] of Object.entries(result.categories)) {
      if (flagged) {
        const score = result.category_scores[category];
        console.log(`  ${category}: ${score.toFixed(4)}`);
      }
    }
  }
  ```

  ```bash cURL theme={null}
  curl https://api.voidai.app/v1/moderations \
    -H "Authorization: Bearer sk-voidai-your_key_here" \
    -H "Content-Type: application/json" \
    -d '{
      "input": "This is a friendly message about programming."
    }'
  ```
</CodeGroup>

### Batch Moderation

<CodeGroup>
  ```python Python theme={null}
  texts = [
      "Hello, how are you today?",
      "I love learning new programming languages!",
      "Let's build something amazing together."
  ]

  response = client.moderations.create(input=texts)

  for i, result in enumerate(response.results):
      print(f"Text {i}: {'Flagged' if result.flagged else 'OK'}")
  ```

  ```typescript TypeScript theme={null}
  const texts = [
    'Hello, how are you today?',
    'I love learning new programming languages!',
    "Let's build something amazing together."
  ];

  const response = await client.moderations.create({ input: texts });

  response.results.forEach((result, i) => {
    console.log(`Text ${i}: ${result.flagged ? 'Flagged' : 'OK'}`);
  });
  ```
</CodeGroup>

### Content Filtering Integration

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="sk-voidai-your_key_here",
    base_url="https://api.voidai.app/v1"
)

def is_content_safe(text, threshold=0.5):
    """Check if content is safe based on moderation scores."""
    response = client.moderations.create(input=text)
    result = response.results[0]

    if result.flagged:
        return False

    # Check if any category score exceeds threshold
    for category, score in result.category_scores.items():
        if score > threshold:
            return False

    return True

def safe_chat(user_message):
    """Chat with content filtering."""
    # Check user input
    if not is_content_safe(user_message):
        return "I'm sorry, I can't respond to that message."

    # Get AI response
    response = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": user_message}]
    )
    ai_message = response.choices[0].message.content

    # Check AI output
    if not is_content_safe(ai_message):
        return "I generated an inappropriate response. Please try again."

    return ai_message

# Usage
result = safe_chat("Tell me about machine learning")
print(result)
```

## Response Example

```json theme={null}
{
  "id": "modr-abc123",
  "model": "text-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "hate": false,
        "hate/threatening": false,
        "harassment": false,
        "harassment/threatening": false,
        "self-harm": false,
        "self-harm/intent": false,
        "self-harm/instructions": false,
        "sexual": false,
        "sexual/minors": false,
        "violence": false,
        "violence/graphic": false
      },
      "category_scores": {
        "hate": 0.00001,
        "hate/threatening": 0.000001,
        "harassment": 0.00002,
        "harassment/threatening": 0.000001,
        "self-harm": 0.000001,
        "self-harm/intent": 0.000001,
        "self-harm/instructions": 0.000001,
        "sexual": 0.00001,
        "sexual/minors": 0.000001,
        "violence": 0.00003,
        "violence/graphic": 0.000001
      }
    }
  ]
}
```

<Info>
  The moderation API is designed to help filter content but should not be the only safety measure in your application. Consider implementing additional safeguards for production systems.
</Info>
