Local development

Webhook connectors need a public HTTPS URL. During development, use the calmlens CLI: it reads your project's events with your API key and forwards each one to a local URL, with the same body, headers and signature as a real webhook delivery. It works with every SDK.

Install the CLI

The CLI comes with the JavaScript SDK: the calmlens package includes it. It needs Node.js 22 or later. Run any command without installing, with npx calmlens, or install it globally:

npm install -g calmlens

In a project that depends on the SDK, npx calmlens runs the CLI that comes with the installed SDK, at the same version.

Without Node.js, install it with Homebrew:

brew tap calmlens/sdks https://github.com/CalmLens/sdks
brew install calmlens/sdks/calmlens

Or download the standalone executable for macOS, Linux or Windows from the CLI releases , check it against SHA256SUMS and add it to your PATH.

Sign in

calmlens login

login shows a code and opens CalmLens in your browser, where you enter the code and choose a project. Only enter a code shown in your own terminal. The CLI keeps the key it receives in your user configuration directory, so later commands need no API key or project ID. Add --read-only to let it only read; trigger needs read and change access. calmlens logout revokes the key and forgets it. You can also disconnect it from your Portal › Profile.

Forward events locally

calmlens listen --forward-to http://localhost:3000/api/webhooks/calmlens --env-file .env.local

Instead of login, you can set CALMLENS_API_KEY and CALMLENS_PROJECT_ID in the environment or in the --env-file file. When either is set, the CLI uses them and ignores your login. It reads CALMLENS_WEBHOOK_SECRET the same way; without one it prints a generated secret to put in your app. Use --events asset.allowed,asset.blocked to forward only some event types. The CLI receives only the events its key has permission to see, and warns at start-up about any requested type the key can't receive, such as asset.review-requested for a Viewer key; see Roles.

A login's key can read asset, usage and review events only. To forward team, API key, connector or upload preset events, use a project API key that holds the permission each type needs.

To create events without uploading your own content, run calmlens trigger [category]. It moderates a harmless test input that CalmLens classifies in the category you name, such as calmlens trigger hate, or as harassment by default; calmlens trigger clean sends text that should be allowed. For every category except clean, pass your project's test input key with --test-key or set CALMLENS_TEST_INPUT_KEY, and turn on Test inputs in the project first; otherwise the code is moderated as ordinary text. Each trigger counts as one upload.

The CLI only forwards events created after it starts, and attempts each delivery once; it doesn't use the connector retry schedule, and its deliveries don't appear in the portal. It reads GET /projects/:projectId/events, which you can also call from your own tools with client.events.list().

Read the events feed

Prefer webhook connectors in production. The events feed suits local development, scripts and backfills, and powers calmlens listen. See Reading the feed for cursor handling.

let { nextCursor: cursor } = await client.events.list();

setInterval(async () => {
  const page = await client.events.list({ cursor });
  for (const event of page.items) console.log(event.type, event.asset?.classification.moderation.status);
  cursor = page.nextCursor;
}, 2000);

Last updated

Signing in

Signing out

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