Skip to main content

Documentation Index

Fetch the complete documentation index at: https://doc.hitopen.com/llms.txt

Use this file to discover all available pages before exploring further.

The moderations endpoint classifies text against a set of content policy categories and returns a flag indicating whether the content violates policy, along with per-category scores. Use it to screen user-generated content before passing it to a model or storing it.

Endpoint

POST https://YOUR_NEWAPI_BASE_URL/v1/moderations

Request parameters

input
string | string[]
required
The text to classify. You can pass a single string or an array of strings to check multiple inputs in one request.
model
string
The moderation model to use. When omitted, the latest stable moderation model is used automatically. Common values include text-moderation-stable and text-moderation-latest.

Response fields

id
string
Unique identifier for the moderation request.
model
string
The moderation model that processed the request.
results
object[]
One result object per input string, in the same order as the input array.

Examples

curl -X POST "https://YOUR_NEWAPI_BASE_URL/v1/moderations" \
  -H "Authorization: Bearer sk-your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "I want to harm someone."
  }'

Checking multiple inputs

Python (batch)
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-token",
    base_url="https://YOUR_NEWAPI_BASE_URL/v1",
)

inputs = [
    "I love sunny days at the park.",
    "How do I make explosives?",
    "Can you help me write a cover letter?",
]

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

for i, result in enumerate(response.results):
    status = "FLAGGED" if result.flagged else "OK"
    print(f"[{status}] Input {i}: {inputs[i][:50]}")

Example response

{
  "id": "modr-abc123",
  "model": "text-moderation-stable",
  "results": [
    {
      "flagged": true,
      "categories": {
        "hate": false,
        "hate/threatening": false,
        "harassment": false,
        "self-harm": false,
        "sexual": false,
        "sexual/minors": false,
        "violence": true,
        "violence/graphic": false
      },
      "category_scores": {
        "hate": 0.0001,
        "hate/threatening": 0.0001,
        "harassment": 0.0023,
        "self-harm": 0.0012,
        "sexual": 0.0001,
        "sexual/minors": 0.0001,
        "violence": 0.9871,
        "violence/graphic": 0.0056
      }
    }
  ]
}