Delivering assets

Serve displayable files and previews in your UI and original files to your servers through the CalmLens CDN, using signed URLs for private assets. See the CDN reference for URL formats and the signing endpoint.

CDN URLs live under:

https://cdn.calmlens.com/v1

Before you serve a file

  • Retain it: set processingOptions.keepContentAfterProcessing: true when uploading.
  • Check availability: follow the delivery checks, including whether content that is still being moderated may be served.
  • Choose access: use public visibility for public files or a signed URL for private files in browsers.

Fetch content with an SDK

Use your server SDK's CDN fetch method with resource: "original" to download a retained file as it was stored: as uploaded, except that images are stored without their embedded metadata unless your project keeps it. The examples reuse the client from your SDK setup or the quick start. This sends the configured API key in one CDN request; you do not need to retrieve the asset or create a signed URL first. Private reads require Download assets permission.

const response = await client.cdn.serve({
  assetId,
  resource: "original",
});

The response body contains the content bytes, not the asset record or moderation report. For a plain-text comment, read the body as text and render it as text. Check the HTTP status before reading a successful body. See the JavaScript CDN methods for Response handling and the other SDK references for their response types.

Keep API keys on your server. Browsers can fetch public URLs directly; for private content, sign an asset URL on your server and send only that URL to the browser.

What the CDN serves

Each asset has these CDN resources:

ResourceServesUse it for
renderedThe asset's one displayable file, described by content.rendered: an image in the best format the browser accepts, a PDF, or browser-safe video or audio Preview. Takes lenses and transforms when it is an image.Showing the asset itself in your UI. The SDKs' CDN fetch methods serve it by default.
previewA still image that stands for the asset, described by content.preview, sized to fit 400 × 400 pixels by default and served in the best format the browser accepts. Takes lenses and transforms.Thumbnails, cards, lists and video posters, for every type that has one.
originalThe stored file, including plain text for comments: the upload's exact bytes, without an image's embedded metadata unless your project keeps it. Never re-encoded, and takes no lens or transform.Downloads, archives and processing that needs the stored bytes.
hls PreviewThe adaptive (HLS) stream of audio or video, described by content.hls, once streaming has prepared it. Takes no lens or transform.Playing audio and video in any HLS player, adapting to the viewer's connection.
embed PreviewA page that shows the asset, for an <iframe>: it plays audio and video, and shows other types in their asset viewer; see Embed media in any site. Takes no lens or transform.Showing assets on other sites, or in your own pages without a viewer of your own.
placeholderA small blurred PNG drawn from the preview; see Show the placeholder to everyone else.Standing in for an asset while it loads or when a viewer may not see it.
infoThe asset's display info as JSON: its type, size, rendered file, preview and stream, and whether this viewer can see it (availability). Not billed as a read.Choosing what to render, and server-side rendering, before loading content.

What rendered and preview serve depends on the asset's type:

Asset typerendered (content.rendered.kind)preview
Imageimage: the image, with HEIC and HEIF convertedThe image
Videovideo Preview: MP4 with H.264 video and AAC audio, up to 1080pA poster frame from one second in Preview
Audioaudio Preview: AAC in M4A, or the upload itself when it is MP3, AAC, M4A or Opus in OggA waveform image Preview
PDF, Office document or presentationpdf: the PDF, or a PDF converted from the documentThe first page or slide
Websiteimage: a screenshot of the top of the pageThe same screenshot
Text, spreadsheetNone: 404 asset/no-rendered-versionNone

content.rendered and content.preview are set exactly when their resource can be served, so check them rather than the asset's type. Video and audio get their browser-safe file and their poster or waveform once the decision is made and only when the content is kept; an upload that already plays in every browser, such as H.264 and AAC in MP4 up to 1080p, is served as uploaded. Until then the field is null and the resource returns 404 asset/no-rendered-version. Rendered video and audio answer Range requests with 206 Partial Content, so players can seek.

Each resource is served only while the asset passes the delivery checks for its current status. Limited assets are served like allowed ones, and age-restricted assets only to the requests your app opts in. While a safety or copyright hold is on, content.rendered, content.preview and content.extractedText are null and the CDN refuses every resource, the placeholder included.

Choose an element

Pick the element from content.rendered.kind, and use the preview for everything smaller than the asset itself:

content.rendered.kindShow it inWith
image<img>A lens or width for the size you show
video<video>The preview as poster
audio<audio>The preview as its waveform, or content.rendered.peaks to draw your own Preview
pdfAn <iframe> or a linkThe preview for its first page
nullThe preview, when content.preview is set, or a file-type iconA link to the original for downloads

When video or audio has content.hls, an HLS player can play the hls stream instead of the file, and the embed page plays it for you in an <iframe>; see Streaming audio and video.

content.preview.thumbhash and content.preview.averageColor describe the preview, and serve as the placeholder for every view of the asset: decode the ThumbHash in the browser, or fill the box with the average colour, while the image, video or PDF loads. The JavaScript SDK's asset component makes these choices for you.

Asset URLs

Each asset has one URL, https://cdn.calmlens.com/v1/assets/{projectId}/{asset}, and every resource is a path beneath it: original files at GET /assets/:projectId/:asset/original, rendered files at GET /assets/:projectId/:asset/rendered, previews at GET /assets/:projectId/:asset/preview and so on. {asset} is the asset ID (asset_…), or ext: followed by its URL-encoded externalId, such as ext:users%2F42%2Favatar. Public assets that meet the prerequisites above can be requested directly.

const response = await client.cdn.serve({
  assetId,
  resource: "original",
});

Private assets require one of the following:

  • A short-lived signed asset URL.
  • An API key with Download assets (assets:download) for the asset's folder, sent in the X-Api-Key header. Enable it on a key in Portal › API keys; it grants access only within that key's project.
  • The portal session of a project member with Download assets for the asset's folder.

Displaying images

Load a rendered URL with a lens or width in a single <img>. The CDN chooses the format from the browser's Accept header, so you don't list formats in a <picture> element:

<img src="https://cdn.calmlens.com/v1/assets/{projectId}/{assetId}/rendered/@thumbnail" alt="" />
RequestFormat served
The browser accepts AVIFAVIF
The browser accepts WebP but not AVIFWebP
No modern format accepted, such as Accept: */* from apps and scriptsThe source format, such as JPEG or PNG, or PNG for formats browsers can't display, such as TIFF or PSD
The lens or transform sets formatThat format, whatever the browser accepts

GIF and WebP sources, which may be animated, are served as WebP rather than AVIF unless the transform sets anim=false, and SVG images keep their format. Responses carry Vary: Accept. A rendered URL the CDN converts to another format counts as an image transform; each variant is billed once however many formats it is served in (see Pricing). A bare rendered URL serves a photo at its full size, so add a lens or a width for feeds, or use the preview resource for thumbnails. For high-density screens, list dpr variants in srcset:

<img
  src="https://cdn.calmlens.com/v1/assets/{projectId}/{assetId}/rendered/width=320"
  srcset="https://cdn.calmlens.com/v1/assets/{projectId}/{assetId}/rendered/width=320,dpr=2 2x"
  alt=""
/>

Rendered images are served without EXIF, XMP or IPTC metadata, such as the location a photo was taken.

In a React, Vue, Svelte or plain HTML front end, the JavaScript SDK's asset component renders this pattern for you from the asset URL, with srcset widths, a placeholder while the image loads and what this viewer may see.

HEIC and HEIF images

An SVG's rendered resource and its preview are a static copy of it, made when they are served: without animations, conditional styles such as media queries, dark mode and hover styles, <switch> alternatives, <foreignObject> content, scripts, event handlers and external references. That static copy is what CalmLens moderates and shows, so display SVGs from rendered. original is the exact upload. CalmLens also moderates what the original can show beyond the static copy: the text and embedded images of every branch, and its other states (each media query and alternative applied, and its animations at each key time). An SVG whose dynamic content can't be evaluated this way, such as motion along a path or styled HTML in a <foreignObject>, or that has too many states to moderate, fails with unsupported-format or too-many-items instead. A browser showing the original still plays its animations in time, between the key times that were moderated.

The rendered resource converts HEIC and HEIF images to a format browsers can display. This applies to image/heic, image/heif, and their sequence variants. Converted images fit within 1920 × 1920 pixels, preserve their aspect ratio, and are never enlarged. The original resource continues to serve the HEIC or HEIF file.

Signed asset URLs

A signed asset URL lets an untrusted client load a private asset for a limited time without receiving an API key or application session. It is the asset's URL with a sig_… grant in place of the asset, and every resource is a path beneath it, as for a public asset. Prefer it for browsers and other clients you do not control.

Sign one on your server with the public API, naming the asset by assetId or externalId. expiresIn sets its lifetime in seconds, and original: true lets it serve /original, the exact uploaded file:

const response = await client.cdn.signAssetUrl({
  "assetId": "asset_5Gm2Rk8XqT3wLp9VbN4c",
  "expiresIn": 900
});

The response contains:

{
  "url": "https://cdn.calmlens.com/v1/assets/proj_8fK2mQx7Lp4NvB3tRz9Y/sig_…",
  "expiresAt": 1760000000000
}

Append the resource you need, such as /rendered/@thumbnail, /preview, /hls/index.m3u8, /embed or /info. See POST /projects/:projectId/signed-asset-urls for request fields, defaults and lifetime limits.

The grant is tied to the project, the asset, whether it serves the original, and its expiry. Lenses, transforms, selectors and viewer claims aren't part of it: add them to the URL as for a public asset. A URL whose expiry has passed returns 403 signed-url/expired, a grant that was changed or is used under another project returns 403 signed-url/invalid, and /original under a grant without original access returns 403 signed-url/original-not-granted. Browsers and other HTTP caches keep a signed response no longer than the URL's expiry. Anyone holding the URL can request any resource or image variant of the asset until it expires.

To apply your own user, tenant or subscription rules before issuing links, or to proxy content through your backend instead, see Asset permissions.

Limited assets

A limited asset is served from its plain URL exactly like an allowed one. The status asks your app to show it without amplifying it, for content such as a one-off insult that shouldn't be removed but shouldn't be promoted either. What reducing its reach means depends on your app:

Your app hasWhat to do with limited content
Feeds or rankingsRank it lower, and keep it out of recommendations, trending and "top" lists.
NotificationsDon't send notifications, mentions or digests for it.
A comment threadCollapse it behind a "Show" control, or sort it to the end.
None of theseShow it like allowed content.

The asset.limited event tells your app when an asset becomes limited, so you can update rankings you've already computed.

Age-restricted assets

Age-restricted content requires viewerClaims.ageConfirmed: true on the CDN request. It defaults to false, including requests authenticated with API keys or signed asset URLs. Your platform confirms the viewer's age; CalmLens does not verify this claim.

viewerClaims is a query parameter or header that anyone requesting a URL, public or signed, can set, so the claim records your platform's age decision rather than restricting access. To control who can load an age-restricted asset, make it private and issue signed asset URLs from your backend only to viewers who pass your age check.

RequestResult for age-restricted content
Claims omitted, or ageConfirmed: false403 viewer/age-confirmation-required
viewerClaims.ageConfirmed: trueServed if all other delivery and access checks pass
API key or signed asset URL without age confirmation403 viewer/age-confirmation-required
Public /placeholderA blurred preview, subject to content and regional restrictions

The same rule applies to originals, rendered files, previews, lenses and transforms. Age confirmation does not grant access to private assets or override a block. Applications that never use age-restricted content should leave it false on display, download and processing paths.

client.cdn.getAssetUrl({ assetId }), client.cdn.signAssetUrl({ assetId }) and the asset component take it as viewerClaims: { ageConfirmed: true }. Viewer region covers the other claim, the HTTP query and header forms, and proxies.

Issue signed asset URLs from your backend

Sign the asset URL once your backend has decided the viewer may see the asset, and add the viewer's claims to the resource URLs you build from it, such as ?viewerClaims=%7B%22ageConfirmed%22%3Atrue%7D for a viewer who passed your age check: the grant alone doesn't confirm age. Signing authorises private access; it does not verify age, and the grant doesn't cover claims. Anyone holding the URL can use it, with any claims, until it expires.

Show the placeholder to everyone else

Every asset with a preview has a /placeholder resource: a small, blurred PNG rendered from content.preview.thumbhash. Show it where the asset would appear:

https://cdn.calmlens.com/v1/assets/{projectId}/{assetId}/placeholder

Let CSS scale it to the asset's size. Placeholders are public, private assets' included, and need no API key, signed URL or age confirmation. A placeholder is served whatever the asset's moderation status, except for purged assets, assets whose content was removed, assets under a safety or copyright hold, assets blocked in the viewer’s region, and assets without a preview. When your project applies regional rules, a placeholder request needs the viewer's country, as a content request does.

A sensitive-media component

Each example renders the placeholder with a notice until your app allows the viewer, then swaps in the opted-in URL. They build both URLs with cdn.getAssetUrl on a CalmLensAppClient from calmlens/app, which needs no API key. viewerClaims.ageConfirmed is your app's own decision. aspectRatio is the image's width divided by its height, which your app stores with the post, so the placeholder fills the same box as the image.

import { CalmLensAppClient } from "calmlens/app";

// Builds public CDN URLs without a request or an API key.
const calmlens = new CalmLensAppClient({ uploadPresetId: "preset_4Lk8Qw2Xm9Rt5Vb3Nc7P" });

type SensitiveImageProps = {
  projectId: string;
  assetId: string;
  status: "allowed" | "limited" | "age-restricted";
  ageConfirmed: boolean;
  alt: string;
  /** Width divided by height, which you store when the image is uploaded. */
  aspectRatio: number;
  onReveal: () => void;
};

const fill = { width: "100%", height: "100%", objectFit: "cover" } as const;

export function SensitiveImage({
  projectId,
  assetId,
  status,
  ageConfirmed,
  alt,
  aspectRatio,
  onReveal,
}: SensitiveImageProps) {
  const restricted = status === "age-restricted";
  const asset = { projectId, assetId };
  return (
    <figure style={{ aspectRatio, margin: 0, position: "relative" }}>
      {!restricted || ageConfirmed ? (
        <img
          // Claims make the response private and uncacheable: send them only when needed.
          src={calmlens.cdn.getAssetUrl({
            ...asset,
            resource: "rendered",
            ...(restricted ? { viewerClaims: { ageConfirmed } } : {}),
          })}
          alt={alt}
          style={fill}
        />
      ) : (
        <>
          <img
            src={calmlens.cdn.getAssetUrl({ ...asset, resource: "placeholder" })}
            alt=""
            style={fill}
          />
          <figcaption
            style={{ position: "absolute", inset: 0, display: "grid", placeContent: "center" }}
          >
            Sensitive content{" "}
            <button type="button" onClick={onReveal}>
              View
            </button>
          </figcaption>
        </>
      )}
    </figure>
  );
}

onReveal should run your app's own check, such as asking the viewer to verify their age, and re-render with viewerClaims.ageConfirmed set once it passes. Apply the same component to thumbnails and previews.

Reviewing blocked assets

Project members with Download assets access can view retained blocked assets in the portal. The portal creates a review link through its internal API, valid for up to 15 minutes. Anyone holding that link can view the content until it expires; it does not require a browser session. Review links also support rendered assets and image transforms, and their responses are not cached.

Ordinary public and signed URLs block assets whose current status is blocked or purged. A past block action does not block an asset that a reviewer has since allowed. Review links cannot access safety-held, deleted, uploading or failed content, or bypass a project's restriction on unmoderated content. The public API and API keys cannot create review links.

Caching and availability

Public responses for projects using only global rules are cacheable, and rendered responses are cached separately for each format. When a project enables regional controls, viewer responses use private, no-store; CalmLens still checks eligibility before reusing its internal cached bytes. Private responses remain private and require authorization on each unsigned request. Updating a lens serves its new version without a manual cache purge.

Every CDN request, including one answered from cache, checks the asset’s current eligibility. When eligibility changes, cached copies are purged and delivery stops within seconds in every region. Browsers and other HTTP caches outside CalmLens may keep previously downloaded content until its Cache-Control lifetime ends. Unavailable private assets generally return 404 to avoid revealing their existence; status-blocked requests return 403 asset/not-available.

Viewer region

The CDN applies the regional rules of the jurisdictions your project serves for each viewer's country, for assets whose outcome differs by region. See Viewer region for passing the country, proxies, signed URLs and caching.

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