CDN API reference

The CalmLens CDN serves retained original files, displayable files, still previews, adaptive streams, embed pages and display info of assets from https://cdn.calmlens.com/v1. Each asset has one URL, and every resource is a path beneath it. Sign an asset URL with the public API to give an untrusted client time-limited access to a private asset.

Guide: Delivering assets, including SDK fetch examples in every language.

The CDN serves each asset according to its current classification.moderation.status: blocked and purged assets are not served, and age-restricted assets need viewerClaims.ageConfirmed: true, including requests with signed URLs or API keys; see Age-restricted assets. Delivery while moderation runs lists every delivery check, including pending content.

Authentication: public assets need no authentication. Private assets need a signed asset URL, or Download assets (assets:download) on the asset's folder, held by a signed-in portal user or by an API key sent in the X-Api-Key header. Signing an asset URL uses a project API key on https://api.calmlens.com/v1. See CDN authentication.

Viewer claims

The SDK accepts viewerClaims: { region: "GB", ageConfirmed: false }. Both fields are optional and are assertions supplied by your application, not verified identity facts: your platform confirms the viewer's age, and CalmLens does not verify this claim. Anyone holding a URL, public or signed, can set them, so they are not an access control: a signed asset URL doesn't cover claims, and your app adds them to any URL (see Age-restricted assets). The CDN defaults ageConfirmed to false and infers the country from the connection reaching it. Through a proxy, explicitly forward the viewer country to avoid using the proxy's country.

For raw HTTP, send viewerClaims as a JSON-encoded query parameter or send the same JSON in X-CalmLens-Viewer-Claims. The query takes precedence. For example, ?viewerClaims=%7B%22region%22%3A%22GB%22%2C%22ageConfirmed%22%3Afalse%7D. Headers suit proxies and fetch clients; URL parameters also work in native browser media elements.

Invalid claims return 400 viewer-claims/invalid. An age-restricted request without confirmation returns 403 viewer/age-confirmation-required. A missing usable country returns 403 viewer/region-required only for an asset whose outcome depends on the viewer's region. Claims do not grant private access or override moderation blocks. See Jurisdiction rules for forwarding, caching and errors.

For each viewer, the CDN applies the strictest of the asset's own decision, the rule for the viewer's country and, for viewers in an EU member state, the EU rule when your project opts into the EU. An asset whose outcome is the same everywhere needs no viewer region. An asset that hasn't been checked against a jurisdiction your project serves, such as the EU after you opt in, returns 403 asset/regional-evidence-required to viewers there; see Existing assets and rollout.

Endpoints

EndpointDescription
POST /projects/:projectId/signed-asset-urlsCreate a short-lived signed URL for a private asset, the base URL of all its CDN resources

CDN URL formats

All paths are relative to https://cdn.calmlens.com/v1. An asset's URL is /assets/{projectId}/{asset}, and each resource is a path beneath it, followed by any selector: /assets/{projectId}/{asset}/{resource}/{selectors}. {asset} is one of:

{asset}Names
asset_…The asset by its ID.
ext:{externalId}The asset by its externalId, URL-encoded, such as ext:users%2F42%2Favatar.
sig_…A signed asset URL's grant, for a private asset or for /original access.

Only content retained with processingOptions.keepContentAfterProcessing: true can be served.

URLReturns
GET /assets/:projectId/:asset/originalThe stored file, including plain text for comments, exactly as stored. Images are stored without their embedded metadata unless your project keeps it.
GET /assets/:projectId/:asset/renderedThe asset's one displayable file, described by content.rendered: an image, a PDF, or browser-safe video or audio. Text and spreadsheets have none and return 404 asset/no-rendered-version.
GET /assets/:projectId/:asset/previewA still image that stands for the asset, described by content.preview, sized to fit 400 × 400 pixels unless a lens or transform sets a size.
GET /assets/:projectId/:asset/hls/index.m3u8 PreviewThe adaptive (HLS) stream of audio or video, described by content.hls: its master playlist, with its media playlists and segments beneath /hls/.
GET /assets/:projectId/:asset/embed PreviewAn HTML page that shows the asset, for an <iframe> on any site: it plays audio and video, and shows other types in their asset viewer.
GET /assets/:projectId/:asset/infoThe asset's display info as JSON, with whether this viewer can see it.
GET /assets/:projectId/:asset/placeholderA small blurred PNG drawn from the preview's ThumbHash, to show in place of an asset a viewer may not see.
GET …/rendered/@:lensIdentifierA rendered image or a preview with a named lens applied, such as /preview/@card.
GET …/rendered/width=1024A rendered image or a preview with a direct transform applied.
GET /assets/:projectId/sig_…/:resourceAny of these resources of a private asset, with any lens or transform, under a signed asset URL. /original only when it was signed with original access.

Every URL also answers HEAD requests, with the status and headers a GET would return and no body. What the CDN serves lists the rendered file and preview of each asset type.

Lens and transform selectors work on /preview and on /rendered when it serves an image. On /original, /embed and /info, on a rendered PDF, video or audio, or when a selector is malformed or names an unknown transform, they return 400 transform/invalid. A known transform with invalid options returns 400 transform-options/invalid, and a lens the project doesn't have returns 404 lens/not-found. See Caching and availability for cache behaviour.

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

Original files

Use GET /assets/:projectId/:asset/original for the uploaded file's exact bytes, such as for downloads and processing. It is never re-encoded and takes no lens or transform.

Rendered assets

Use GET /assets/:projectId/:asset/rendered to display an asset in the element content.rendered.kind names. Without an explicit format, images are served as AVIF or WebP when the request's Accept header allows it, and otherwise in the source format; responses carry Vary: Accept. See Displaying images.

Rendered video and audio answer Range requests with 206 Partial Content and carry Accept-Ranges: bytes, so players can seek and stream them.

For named lenses, one-off transform selectors, and supported image options, see Lenses and transforms.

Previews

Use GET /assets/:projectId/:asset/preview for thumbnails, cards, posters and lists: it is always a still image, in the best format the browser accepts, whatever the asset's type. Without a size of its own, it scales down to fit within 400 × 400 pixels; a lens or transform that sets width or height replaces that size.

Adaptive streams

Adaptive streamsPreview

Use GET /assets/:projectId/:asset/hls/index.m3u8 to play audio or video with an HLS player once streaming has prepared it and content.hls is set; until then it returns 404 asset/no-rendered-version. The master playlist lists a media playlist for each rendition, and they list fragmented MP4 (CMAF) segments, all beneath /hls/. Playlists list their files by relative paths, so under a signed asset URL every file is requested beneath the same grant and players need only the master playlist's URL. Each playlist also carries the request's viewer claims on its files.

Stream files carry Access-Control-Allow-Origin: *, and segments answer Range requests. Segments are cached like other files; playlists carry the request's viewer claims, so only the viewer's browser keeps them, for up to a minute. Each file passes the same delivery checks as the other resources. Lenses and transforms don't apply.

Embed pages

Embed pagesPreview

Use GET /assets/:projectId/:asset/embed as the src of an <iframe>: an HTML page that plays audio and video (the stream when the asset has one, the rendered file otherwise, with its poster or waveform) and shows other assets in the asset viewer for their type. Any site may frame it (frame-ancestors *), and it is sent with Cache-Control: private, no-store and Referrer-Policy: no-referrer. The files the page loads carry its viewer claims and are under a grant that expires with its own URL's, and they don't count as reads again. A delivery check that fails, an age-restricted asset without viewerClaims.ageConfirmed: true, and an asset with nothing to show yet each show a status message in the page instead of an error body; see Embed media in any site. The page takes no lens or transform.

Display info

Use GET /assets/:projectId/:asset/info to learn what to show before loading content: a JSON subset of the asset object, with the same field names, plus availability for the request's viewer claims. It holds the asset's id, projectId, type and externalUrl (a website's page, for a link to it), and from content its format (the uploaded MIME type, which tells a spreadsheet from other documents), width, height, durationSeconds, pageCount, rendered, preview and hls.

{
  "id": "asset_5Gm2Rk8XqT3wLp9VbN4c",
  "projectId": "proj_8fK2mQx7Lp4NvB3tRz9Y",
  "type": "video",
  "externalUrl": null,
  "content": {
    "format": "video/quicktime",
    "width": 1920,
    "height": 1080,
    "durationSeconds": 94.2,
    "pageCount": null,
    "rendered": { "kind": "video", "format": "video/mp4", "width": 1920, "height": 1080 },
    "preview": { "width": 1280, "height": 720, "thumbhash": null, "averageColor": null },
    "hls": { "renditions": [] }
  },
  "availability": "available"
}

availability is available, age-restricted (until the viewer's age is confirmed with viewerClaims.ageConfirmed: true) or unavailable (held, blocked in the viewer's region, not yet moderated or removed). It is decided by the same checks the CDN applies to the content, so the content resources refuse exactly what it reports as not available. The response never includes moderation results, metadata, names, tags or extracted text. On your server, client.cdn.getAssetInfo(assetUrl) reads it for an asset URL, public or signed, so a page can render the asset component with its info on the first request.

Display info is cached at the edge and withdrawn with the asset's other cached responses, carries Access-Control-Allow-Origin: *, and is not billed as a read. A private asset's display info needs a signed asset URL, or the same session or API key access as its content.

Placeholders

Show GET /assets/:projectId/:asset/placeholder in place of an age-restricted or blocked asset. It is public for every asset, private ones included, and needs no authentication or signature. It is served whatever the moderation status, except for purged assets. It is not served for assets whose content was removed, assets under a safety or copyright hold, assets without a preview, or viewers in a jurisdiction whose rules block the asset. Lenses and transforms do not apply; age confirmation is not required for the blurred placeholder.

CDN errors

StatusCodeDescription
400viewer-claims/invalidSupply valid viewer claims with an uppercase ISO country code and a boolean age confirmation. EU is a jurisdiction, not a viewer country.
403viewer/age-confirmation-requiredYour application must confirm the viewer passed its age check before requesting age-restricted content, including requests with API keys or signed URLs.
403viewer/region-requiredRegional controls apply but neither an explicit viewer country nor a usable connection country is available.
403asset/regional-evidence-requiredThe asset was uploaded before the project served a jurisdiction whose rules its results don't cover, so it isn't delivered to viewers there. Existing assets aren't checked again; upload the content again to check it.
403asset/not-availableThe asset is blocked by its status, a safety hold, or unavailable stored content. A private asset requested without access returns 404 instead, so its existence isn't revealed.
404asset/no-rendered-versionThe asset is deliverable but has no rendered version: a text asset, or a document or website whose page image isn't available. Request its original resource instead.
403signed-url/expiredThe signed asset URL's grant is valid but its expiry has passed. Sign a new asset URL on your server.
403signed-url/invalidThe URL's `sig_…` grant wasn't signed by CalmLens for this project: it was changed after signing, or used under another project's URL. Use the signed asset URL exactly as returned, adding only resources, selectors and viewer claims.
403signed-url/original-not-grantedThe signed asset URL was signed without original access, so it doesn't serve `/original`. Sign it with `original: true` to serve the uploaded file.
403auth/permission-deniedThe API key lacks the Download assets (assets:download) permission for the asset's folder.
404lens/not-foundThe URL names a lens that doesn't exist in the project.
400transform/invalidThe transform selector is malformed or names an unknown transform type.
400transform-options/invalidThe transform options do not match the supported option schema.

A transform that fails to process returns 403 asset/not-available with HTTP status 500, rather than the usual 403. An unknown asset returns 404 asset/not-found.

Signed asset URLs

A private asset is delivered through a signed asset URL: its asset URL with a sig_… grant in place of the asset, such as https://cdn.calmlens.com/v1/assets/proj_…/sig_…. Sign one on your server with POST /projects/:projectId/signed-asset-urls, by asset ID or externalId, and append resources to it exactly as to a public asset's URL.

  • A grant is tied to the project, the asset, whether it serves /original, and its expiry, from 1 second to 24 hours (15 minutes by default). Under another project's URL it returns 403 signed-url/invalid, as does a grant that was changed; once expired it returns 403 signed-url/expired.
  • Without original access, /original returns 403 signed-url/original-not-granted. Every other resource is served either way.
  • Lenses, transforms, selectors and viewer claims aren't part of the grant: add them to the URL as for a public asset. Anyone holding the URL can request other image variants of the asset until it expires.

The signed asset URL object

SignedAssetUrl
urlstring
The signed asset URL. Append a resource, as to a public asset's URL: /rendered, /preview, /hls/index.m3u8, /embed, /info, and /original when it was signed with original access. Lenses, transforms and viewer claims are added the same way and aren't part of the signature.
expiresAtnumber
When the URL expires, in milliseconds since the Unix epoch

Endpoint details

Sign Asset URL

Create a short-lived signed URL for a private asset, the base URL of all its CDN resources

OpenAPI YAML
POST
https://api.calmlens.com/v1/projects/
/signed-asset-urls
const response = await client.cdn.signAssetUrl({
  "assetId": "asset_5Gm2Rk8XqT3wLp9VbN4c",
  "expiresIn": 900
});

Request Body

Edit any value to update the generated request examples.

number
Lifetime of the URL in seconds, from 1 second to 24 hours
boolean
Whether the URL serves /original, the exact uploaded file. Every other resource is served either way.
string (optional)
The asset to sign a URL for. Send this or externalId.
string (optional)
Or your identifier for the asset, as it was uploaded. Send this or assetId.

Response


Error Codes

401api-key/missing
Authentication required. Send your project API key in the X-Api-Key header.
401api-key/invalid
The API key is invalid, revoked or expired. Create a key under Developer → API Keys.
403api-key/project-mismatch
This API key belongs to a different project. Use a key created for the project that owns this resource.
403auth/permission-denied
This API key lacks a permission the request needs (details.permission names it, such as assets:download for an asset's folder), or the resource belongs to another project.
400validation/invalid-request
The request's parameters, query or body are invalid. details.issues lists each problem, with its path and issue code.
415request/unsupported-content-type
Send the request body as application/json.
404asset/not-found
Asset not found
423asset/held
The asset is held and this request can't change or deliver it. details.hold is `safety` for a safety hold or `copyright` for a copyright claim.
404project/not-found
Project not found
500server/internal-error
An internal error occurred. Retry later, and quote requestId to support.

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