An AI-powered content moderation API that analyzes text for harmful content using multiple AI providers and two analysis modes.
- Single mode — Analyzes a single text using Hugging Face's
toxic-bertmodel - Context mode — Analyzes a full conversation with context awareness using LLMs (Groq, Gemini, OpenAI)
- Multi-provider architecture — switch AI providers via environment variable
- Moderation history with filtering and pagination
- Statistics endpoint
- Rate limiting
- Swagger documentation
- Node.js 18+
- PostgreSQL
- Clone the repository
```bash git clone https://github.com/Aello1/moderation-api.git cd moderation-api ```
- Install dependencies
```bash npm install ```
- Create your
.envfile
```bash cp .env.example .env ```
-
Fill in your credentials in
.env -
Set up the database
```bash npx prisma db push ```
- Start the server
```bash npm run dev ```
Swagger UI available at http://localhost:3000/docs
```json POST /api/moderate { "mode": "single", "text": "I hate you" } ```
```json POST /api/moderate { "mode": "context", "messages": [ { "username": "alice", "role": "user", "content": "hey" }, { "username": "bob", "role": "user", "content": "I will destroy you" } ] } ```
``` GET /api/logs?flagged=true&action=block&page=1&limit=10 ```
``` GET /api/stats ```
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | — |
HF_API_KEY |
Hugging Face API key | — |
GROQ_API_KEY |
Groq API key | — |
AI_PROVIDER |
AI provider for context mode (groq) |
groq |
PORT |
Server port | 3000 |
- TypeScript + Node.js
- Express
- PostgreSQL + Prisma
- Hugging Face — toxic-bert
- Groq — Llama 3.3 70B
- Swagger UI
Note: Gemini provider may not be available in all regions due to Google API restrictions.
MIT with Commons Clause — free for non-commercial use. Contact for commercial licensing.