import ModerationAPI from "@moderation-api/sdk";
// Option 1: Use environment variable MODAPI_SECRET_KEY
const moderationApi = new ModerationAPI();
// Option 2: Pass key explicitly
// const moderationApi = new ModerationAPI({ secretKey: 'proj_...' });
// Submit text for moderation
const result = await moderationApi.content.submit({
content: {
type: "text",
text: "Hello world!",
},
contentId: "message-123",
authorId: "user-123",
conversationId: "room-456",
metadata: {
customField: "value",
},
});
// Simple boolean check
if (result.evaluation.flagged) {
console.warn("Text content flagged");
// Block the content, show an error, etc...
}
// Use the API's recommendation (considers severity, thresholds, and more)
switch (result.recommendation.action) {
case "reject":
console.log("Content should be rejected");
break;
case "review":
console.log("Content needs manual review");
break;
case "allow":
console.log("Content is approved");
break;
}