Add content moderation with Moderation API to every place where users create
content (posts, comments, messages, profiles).
- Call it from server code only (an API route, server action, edge or server
function), never from the browser. Read the key from the MODAPI_SECRET_KEY
secret. Never put the key in client code.
- Send each piece of content before you save it:
POST https://api.moderationapi.com/v1/moderate
Authorization: Bearer <MODAPI_SECRET_KEY>
Body: {"content": {"type": "text", "text": "<the text>"}, "authorId": "<user id>"}
- Read recommendation.action from the response:
- "allow": save and publish.
- "review": save it but do not publish it yet. A moderator decides.
- "reject": do not save it. Show the user a short, neutral message.
Treat any other value as "review".
- If the request fails, save and publish the content, so users are not blocked.
Docs: https://docs.moderationapi.com/llms.txt