Quick start
CalmLens tells your app whether user content is safe to show. Start with Choose your integration to find the flow for your app, or try a check below.
Try it without code
Paste a comment and see what CalmLens decides with your project's policy, and why. Each check is a normal upload, so it counts towards your usage and free uploads.
Sign in to try it here with your project's policy.
Set up your app
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 › API keys, create a key and copy it, then copy your Project ID. 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
import { CalmLensServerClient } from "calmlens/server";
const client = new CalmLensServerClient({
apiKey: (process.env.CALMLENS_API_KEY ?? ""),
projectId: (process.env.CALMLENS_PROJECT_ID ?? ""),
});
2. Moderate a comment
client.text.classify() waits for the decision before your app continues:
async function createComment(comment: { id: string; body: string }) {
const result = await client.text.classify({ text: comment.body, externalId: `comment-${comment.id}` });
const { status, flaggedCategories } = result.classification.moderation;
// Attach to the pre-created pending version; preserve newer webhook decisions.
await saveComment({ ...comment, assetId: result.id, status });
if (status === "allowed" || status === "limited" || status === "age-restricted") {
return Response.json({ id: comment.id, status }, { status: 201 });
}
return Response.json(
{ code: "comment/refused", categories: flaggedCategories },
{ status: 422 },
);
}
Save each comment with its status and show it as Use the decision describes; keep a comment whose request fails or returns a status your app doesn't recognise unpublished.
Save the comment as pending in your database before the call. Give each version of the comment (the original and each edit) its own ID and use it in externalId, because an externalId can be used only once in a project; in the example, comment.id is that version ID. The example’s saveComment helper then attaches the asset and status to the saved comment. A later decision can arrive by webhook, so it must not overwrite a newer status. See Moderate comments and posts for publication and webhook handling.
3. Moderate an image
client.assets.create() returns an asset ID straight away while moderation runs. The example sets externalId to the post's own ID, so later events name the post. Keep the post unpublished until it's allowed. To serve the image from CalmLens, see Choose where files live.
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.classification.status is "processing"; save asset.id with the post
4. Receive the result
In Portal › Webhooks & connectors, subscribe your HTTPS endpoint to asset.allowed, asset.limited, asset.age-restricted, asset.blocked, asset.purged and asset.failed. Match the event's asset.externalId to your post and store its status. See Webhooks.
Choose where files live
Pick whether CalmLens keeps and serves the files after checking them, and how your pages show them. Text such as comments needs none of this: store it with your record and show it once it's allowed.
Show files with the asset component
Use this in a React, React Native, Vue, Svelte or plain HTML front end when CalmLens hosts the files your users see. The component handles every moderation status, so your pages need no status logic of their own.
1. Keep files after moderation
Upload with processingOptions.keepContentAfterProcessing: true, or turn on Keep content after moderation on your upload preset. Choose each asset's visibility: public files load from the CDN directly, and private ones need a signed asset URL from your server.
2. Add the asset component
Pass the asset URL your server sends with the page: client.cdn.getAssetUrl({ assetId }) for a public asset, or client.cdn.signAssetUrl({ assetId }) for a private one. Available files load from the CDN with a placeholder while they load, age-restricted ones stay behind a notice until your app sets viewerClaims.ageConfirmed, and files the viewer can't see show an unavailable notice without requesting the file:
import { CalmLensAsset } from "calmlens/react";
type PostPhotoProps = {
assetId: string;
/** The asset URL your server sent with the post: public, or signed for a private asset. */
src: string;
alt: string;
/** Width divided by height, which you store when the image is uploaded. */
aspectRatio: number;
ageConfirmed: boolean;
onReveal: () => void;
};
// Your server signs a private asset's URL again with cdn.signAssetUrl once it expires.
async function refreshUrl(assetId: string): Promise<string> {
const response = await fetch(`/api/photos/${assetId}/url`);
if (!response.ok) throw new Error(`Couldn't refresh the photo (${response.status})`);
return (await response.json()).url;
}
export function PostPhoto({
assetId,
src,
alt,
aspectRatio,
ageConfirmed,
onReveal,
}: PostPhotoProps) {
return (
<CalmLensAsset
src={src}
onExpired={() => refreshUrl(assetId)}
viewerClaims={{ ageConfirmed }}
onAgeConfirmRequest={onReveal}
alt={alt}
aspectRatio={aspectRatio}
image={{ widths: [400, 800], sizes: "(min-width: 768px) 50vw, 100vw" }}
/>
);
}
Asset component covers server rendering, responsive widths, lenses, video, audio and documents.
Link assets to your records
Set each asset's externalId to the ID of the post, comment or profile it belongs to. Events carry it, CDN URLs accept it and it's unique within a project, so your app can find its own record without storing a mapping. Save the asset ID too if you'll call the API for that asset. See External IDs.
Use the decision
classification.moderation.status is the decision for everyone; jurisdiction rules can make it stricter for viewers in some countries. For each status:
- allowed: publish it. To serve files from CalmLens, see Delivering assets.
- limited: publish it without amplifying it; see Limited assets.
- age-restricted: show it only to the viewers your app allows; see Age-restricted assets.
- blocked or purged: don't publish it, and tell the author.
- pending: keep it unpublished until the decision arrives.
Using the decision covers what to show the author and everyone else for each status, and Webhooks covers decisions that change after you publish.
Test moderation outcomes safely
Use test inputs to check how your app handles each status without uploading real harmful content.
Next steps
- Guides: end-to-end walkthroughs for an upload component, comments and posts, sensitive media and profile pictures.
- Examples: runnable apps, such as Calmgram, that moderate and serve content end to end.
- How CalmLens works: the concepts in one page.
- Policies and actions: choose what gets blocked or age-restricted.
- AI assistants: connect an assistant or coding tool over MCP to moderate content and look up decisions from it.