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. In the API key created dialog, select Copy API key and save the complete value to your server configuration or secret manager before selecting Done. The list shows the key's prefix for identification. If you closed the dialog without saving the key, rotate it.

  • 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 expiry.
  • 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. Configurator suits a setup or deploy script: it can do everything Editor can, and also manage lenses, upload presets, policies (including choosing the project's policy), metadata fields and project settings, without managing members, API keys, connectors or the project itself. 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.

PermissionAdministratorConfiguratorEditorViewer
View assets assets:readYesYesYesYes
Download assets assets:downloadYesYesYesYes
Upload assets assets:createYesYesYesNo
Edit and move assets assets:updateYesYesYesNo
Delete assets assets:deleteYesYesYesNo
Share assets assets:shareYesYesYesNo
Browse folders folders:readYesYesYesYes
Create folders folders:createYesYesYesNo
Rename folders folders:updateYesYesYesNo
Delete empty folders folders:deleteYesYesYesNo
View project settings settings:readYesYesNoNo
Change project settings settings:writeYesYesNoNo
View members members:readYesYesYesYes
Invite and manage members members:writeYesNoNoNo
View API keys api-keys:readYesNoNoNo
Manage API keys api-keys:writeYesNoNoNo
View webhooks and connectors connectors:readYesNoNoNo
Manage webhooks and connectors connectors:writeYesNoNoNo
View metadata fields metadata:readYesYesYesNo
Manage metadata fields metadata:writeYesYesNoNo
View lenses lenses:readYesYesYesYes
Manage lenses lenses:writeYesYesNoNo
View upload presets upload-presets:readYesYesYesNo
Manage upload presets upload-presets:writeYesYesNoNo
View hash lists hash-lists:readYesYesYesNo
Manage hash lists hash-lists:writeYesYesYesNo
View moderation policies policies:readYesYesYesYes
Manage moderation policies policies:writeYesYesNoNo
View reviews reviews:readYesYesYesNo
Review content reviews:writeYesYesYesNo
Manage project project:manageYesNoNoNo

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. The portal asks you to confirm before saving a key that manages the project, its members or API keys, or that can delete assets or folders anywhere in the project.

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, and details.role names the lowest role that includes it, such as configurator for lenses:write. 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.

A 403 with the plain text body error code: 1010 isn't an authentication error. The request was refused before its key was checked, because of its User-Agent. Clients must send a User-Agent that names your app; the SDKs do this for you.

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