Quick start

Send user content to the CalmLens API to see which action your moderation policy applies. Start with Choose your integration to find the flow for your app, or try a check below.

Build with agents

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

On your first sign-in, a setup dialog over the sign-in background takes you through your project name, community policy, and storage and delivery choices. Keep content starts on for new projects. Choose Delete after processing if you only need the asset record and moderation results. You can change this later in Project settings → Project defaults.

The API and SDK option is retainContent. Upload presets inherit the project setting unless they override it, and server uploads can override that choice for an individual upload. Existing projects keep their previous retention behaviour.

First-project setup restores your step and choices if you reload the same tab. When setup is complete, try an upload, connect your server with an API key, or configure browser uploads. Use New project in the project switcher to open the same setup dialog over the portal for another project. You can close it and return to your work; unsaved choices require confirmation before being discarded.

Pick how content reaches CalmLens. The steps below change to match, and you only need one of them.

How will content reach CalmLens?

Upload from a browser or app, signed by your server

Use this when users upload files from your web or mobile app. Files go straight to CalmLens, so your server never handles them, but your server still decides who may upload.

1. Create an upload preset

In Portal › Upload presets, create a preset that accepts only uploads your server signs a token for. Set the file types and maximum size it accepts, the folder uploads go to and whether uploaders see the decision, and keep content after moderation if you'll serve the files from CalmLens. Your server uses the preset's ID. See Upload presets for every setting.

2. Sign upload tokens on your server

Add an endpoint that checks the signed-in user, commits a pending upload record with a unique externalId, then returns a token. client.uploadTokens.sign({ uploadPresetId, externalId, expiresIn }) signs it locally with your API key, without a request to CalmLens. Each token uploads one file and expires after 10 minutes unless you choose otherwise. Return token from your endpoint.

const { token, expiresAt } = await client.uploadTokens.sign({
  uploadPresetId: "preset_4Lk8Qw2Xm9Rt5Vb3Nc7P",
  externalId: "post-42",
  expiresIn: 600,
});

The asset gets the token's externalId, so you can match it to the post later.

3. Add the upload widget

Install calmlens in your front end. The SDK's upload widget fetches a token from your endpoint for each file, uploads it with progress, shows the uploader the moderation decision and gives your app the asset ID:

import { type CalmLensUpload, CalmLensUploader } from "calmlens/react";

export function PhotoUploader({ onUploaded }: { onUploaded: (upload: CalmLensUpload) => void }) {
  return (
    <CalmLensUploader
      uploadPresetId="preset_4Lk8Qw2Xm9Rt5Vb3Nc7P"
      tokenUrl="/api/upload-token"
      accept="image/*"
      maxFileSize={10 * 1024 * 1024}
      onUploaded={onUploaded}
    />
  );
}

Send the asset ID to your server with the rest of the post. Upload widget covers its options, translations and styling. To build your own interface instead, see Uploading from a browser.

4. Receive the result on your server

Subscribe your server to asset.allowed, asset.limited, asset.age-restricted, asset.blocked and asset.purged in Portal › Webhooks & connectors, plus asset.failed for processing failures. Match the event's asset.externalId to your post and store its status. Trust only the decision your server receives: users can change what their browser reports.

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.

Where will your files live?

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.retainContent: 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.

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.decision 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.
  • null: the asset is still processing or failed; keep it unpublished until a 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

Last updated

Cookies on CalmLens

We use essential cookies for sign-in and security. With your permission, functional cookies remember your preferences and Google Analytics measures website use and signups. Optional ad measurement cookies link Google ad clicks to signups. Personalised advertising stays off. Manage cookies