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

# Moderations

> Classify text content for safety violations

The Moderations API helps detect potentially harmful content in text.

## Create Moderation

`POST /moderations`

Classify a text to see if it violates OpenAI's usage policies.

### Request Body

<ParamField body="input" type="string | array" required>
  The input text to classify
</ParamField>

<ParamField body="model" type="string">
  The moderation model to use (e.g., "text-moderation-latest", "text-moderation-stable")
</ParamField>

### Response

Returns a moderation object with classification results.

### Example

<CodeGroup>
  ```javascript Node.js theme={null}
  const response = await fetch('https://api.electronhub.ai/v1/moderations', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      input: 'I want to hurt someone.',
      model: 'text-moderation-latest'
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.electronhub.ai/v1/moderations',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
      },
      json={
          'input': 'I want to hurt someone.',
          'model': 'text-moderation-latest'
      }
  )

  print(response.json())
  ```

  ```bash cURL theme={null}
  curl -X POST "https://api.electronhub.ai/v1/moderations" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "input": "I want to hurt someone.",
      "model": "text-moderation-latest"
    }'
  ```
</CodeGroup>

### Response Format

The response contains the following fields:

* `id`: Unique identifier for the moderation request
* `model`: The model used for moderation
* `results`: Array of result objects with the following properties:
  * `flagged`: Whether the content was flagged
  * `categories`: Object with boolean values for each category
  * `category_scores`: Object with confidence scores for each category

### Categories

The moderation model checks for the following categories:

* **hate**: Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste
* **hate/threatening**: Hateful content that also includes violence or serious harm towards the targeted group
* **harassment**: Content that expresses, incites, or promotes harassing language towards any target
* **harassment/threatening**: Harassment content that also includes violence or serious harm towards any target
* **self-harm**: Content that promotes, encourages, or depicts acts of self-harm
* **self-harm/intent**: Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm
* **self-harm/instructions**: Content that encourages performing acts of self-harm
* **sexual**: Content meant to arouse sexual excitement
* **sexual/minors**: Sexual content that includes an individual who is under 18 years old
* **violence**: Content that depicts death, violence, or physical injury
* **violence/graphic**: Content that depicts death, violence, or physical injury in graphic detail


## OpenAPI

````yaml POST /moderations
openapi: 3.0.1
info:
  title: Electron Hub API
  description: >-
    Unified API platform integrating 200+ AI models for chat, image generation,
    speech-to-text, embeddings, and more.
  version: 1.0.0
  contact:
    name: Electron Hub Support
    email: support@electronhub.ai
    url: https://discord.com/invite/electronhub
  license:
    name: MIT
servers:
  - url: https://api.electronhub.ai/v1
    description: Production API v1
security:
  - bearerAuth: []
paths:
  /moderations:
    post:
      summary: Create Moderation
      description: Check content for moderation
      operationId: createModeration
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ModerationRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ModerationResponse'
components:
  schemas:
    ModerationRequest:
      type: object
      required:
        - model
        - input
      properties:
        model:
          type: string
          example: text-moderation-latest
        input:
          oneOf:
            - type: string
            - type: array
              items:
                oneOf:
                  - type: string
                  - type: object
    ModerationResponse:
      type: object
      required:
        - id
        - model
        - results
      properties:
        id:
          type: string
        model:
          type: string
        results:
          type: array
          items:
            $ref: '#/components/schemas/ModerationResult'
    ModerationResult:
      type: object
      required:
        - flagged
        - categories
        - category_scores
      properties:
        flagged:
          type: boolean
        categories:
          type: object
          properties:
            sexual:
              type: boolean
            hate:
              type: boolean
            harassment:
              type: boolean
            self-harm:
              type: boolean
            sexual/minors:
              type: boolean
            hate/threatening:
              type: boolean
            violence/graphic:
              type: boolean
            self-harm/intent:
              type: boolean
            self-harm/instructions:
              type: boolean
            harassment/threatening:
              type: boolean
            violence:
              type: boolean
        category_scores:
          type: object
          properties:
            sexual:
              type: number
            hate:
              type: number
            harassment:
              type: number
            self-harm:
              type: number
            sexual/minors:
              type: number
            hate/threatening:
              type: number
            violence/graphic:
              type: number
            self-harm/intent:
              type: number
            self-harm/instructions:
              type: number
            harassment/threatening:
              type: number
            violence:
              type: number
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Enter your API key (starts with 'ek-')

````