Authentication

Configure a server SDK once with your project API key and project ID using the quick start or your SDK reference. Other examples reuse that client; it sends the authentication header for you. Without an SDK, send the key in the X-Api-Key header of every request; see the API reference.

import { CalmLensServerClient } from "calmlens/server";

const client = new CalmLensServerClient({
  apiKey: (process.env.CALMLENS_API_KEY ?? ""),
  projectId: (process.env.CALMLENS_PROJECT_ID ?? ""),
});
const page = await client.assets.list();
console.log(page);

Create and protect keys

Create keys under Portal › API keys. The complete key is shown only when it is created.

  • Keep keys on a server or in a secret manager, never in browser bundles or source control.
  • Give each integration its own named key so it can be revoked independently.
  • Treat a revoked or expired key as unusable and rotate clients before expiration.
  • A key is project-scoped. The project in the URL must match the key's project.

Rotate a key

  1. Create a replacement with the permissions your integration needs.
  2. Update the secret in your server environment and deploy it.
  3. Verify a request succeeds with the replacement, then revoke the old key.

Choose permissions

Integration needsGrant
Submit contentUpload assets (assets:create) in the relevant project or folders.
Read reportsView assets (assets:read) in the relevant scope.
Fetch private filesDownload assets (assets:download).
Upload public assets, change an asset's visibility, or give browsers private access with signed URLsShare assets (assets:share), in addition to the permission for the upload or change itself.

Use Members and permissions for custom folder scopes.

Roles

A key, like a member, gets a standard role or custom permissions. Editor suits an integration that uploads and moderates content: it can manage assets, folders and hash lists, view and decide the review queue, and view the upload presets, metadata fields, lenses, policies and members it works with. Viewer only reads. Administrator holds every project permission. A key receives the events whose permission it holds, so an Editor key receives asset.review-requested but not API key or connector events.

PermissionAdministratorEditorViewer
View assets assets:readYesYesYes
Download assets assets:downloadYesYesYes
Upload assets assets:createYesYesNo
Edit and move assets assets:updateYesYesNo
Delete assets assets:deleteYesYesNo
Share assets assets:shareYesYesNo
Browse folders folders:readYesYesYes
Create folders folders:createYesYesNo
Rename folders folders:updateYesYesNo
Delete empty folders folders:deleteYesYesNo
View project settings settings:readYesNoNo
Change project settings settings:writeYesNoNo
View members members:readYesYesYes
Invite and manage members members:writeYesNoNo
View API keys api-keys:readYesNoNo
Manage API keys api-keys:writeYesNoNo
View webhooks and connectors connectors:readYesNoNo
Manage webhooks and connectors connectors:writeYesNoNo
View metadata fields metadata:readYesYesNo
Manage metadata fields metadata:writeYesNoNo
View lenses lenses:readYesYesYes
Manage lenses lenses:writeYesNoNo
View upload presets upload-presets:readYesYesNo
Manage upload presets upload-presets:writeYesNoNo
View hash lists hash-lists:readYesYesNo
Manage hash lists hash-lists:writeYesYesNo
View moderation policies policies:readYesYesYes
Manage moderation policies policies:writeYesNoNo
View reviews reviews:readYesYesNo
Review content reviews:writeYesYesNo
Manage project project:manageYesNoNo

A permission that manages a feature includes viewing it, and Manage project includes every project configuration permission. For anything else, such as an Editor key that also manages lenses, use custom permissions.

CDN access

Public assets need no authentication. Private assets need a short-lived signed URL, which suits browsers and other untrusted clients, or a key with Download assets; see Asset URLs.

Authentication failures

The key is checked before the request is validated, so an authentication error comes first. Authentication errors use the same JSON body as other request errors. Branch on its code:

ErrorWhat to do
401 api-key/missingSend your project API key in the X-Api-Key header.
401 api-key/invalidThe key is unknown, revoked or expired. Check for typos or whitespace, or create a new key under Portal › API keys.
403 api-key/project-mismatchThe key belongs to a different project. Use a key created for the project in the URL, or the project that owns the asset or folder.
403 auth/permission-deniedThe key is valid but lacks a permission the request needs, such as Delete assets for the asset's folder. When CalmLens knows which one, details.permission names it, such as assets:delete, with details.folderId for a folder grant. Give the key that permission under Portal › API keys, or use a key that has it.
403 api-key/not-acceptedAPI keys are accepted only by the public API under https://api.calmlens.com/v1. Send the request to the documented endpoint instead of a portal-only address.

Do not retry 401 or 403 responses with the same key; fix the configuration first.

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