Quick start
CalmLens tells your app whether user content is safe to show. Pick how content reaches CalmLens. The steps below change to match, and you only need one of them.
Upload from your server
Use this when your backend already receives the content, or when you're moderating text such as comments and messages.
1. Get an API key and your project ID
In Portal › Developer › API Keys, create a key and copy it, then copy the Project ID shown next to it. Store both on your server, for example as CALMLENS_API_KEY and CALMLENS_PROJECT_ID. Never put the key in browser or mobile app code.
npm install @calmlens/sdk
import { CalmLensServerClient } from "@calmlens/sdk/server";
const client = new CalmLensServerClient({
apiKey: process.env.CALMLENS_API_KEY!,
projectId: process.env.CALMLENS_PROJECT_ID!,
});
2. Moderate a comment
client.text.moderate() waits for the decision before your app continues.
const result = await client.text.moderate({ text: comment.body, externalId: `comment-${comment.id}` });
if (result.status === "approved") {
await publishComment(comment);
} else {
showError("Your comment wasn't posted because it may break our community guidelines.");
}
3. Moderate an image
client.assets.create() returns an asset ID straight away while moderation runs. Save the ID with the post and keep the post hidden until it's approved.
const asset = await client.assets.create({
name: file.name,
content: { data: file, type: file.type }, // a File or Blob; base64 and buffers also work
externalId: `post-${post.id}`,
});
// asset.status is "pending"; save asset.id with the post
4. Receive the result
In Portal › Webhooks & connectors, subscribe your HTTPS endpoint to asset.classified and asset.failed. Match the event's asset ID to your post, then publish or remove it. See Webhooks.
Read the decision
Your project's moderation policy turns each report into an action. Your app only needs two fields:
status | report.flagged | What your app should do |
|---|---|---|
| approved | false | Publish. |
| approved | true | Publish, and add it to a review queue. The policy action was alert. |
| rejected | true | Don't publish. Tell the author it wasn't posted. The action was hide or purge. |
| pending | N/A | Still being classified. Keep it unpublished and wait. |
| error | N/A | Classification failed. Don't publish; retry or review manually. |
Try a rejection safely
Use test inputs to check your rejection flow without uploading real harmful content.
Next steps
- How CalmLens works: the concepts in one page.
- Policies and actions: choose what gets hidden.
- Delivering assets: serve approved files from CalmLens.