Lenses API reference

Use a project API key to list, create, update and delete the project's lenses. The ensure endpoint creates or updates lenses by identifier and returns an unchanged lens as it is, so you can run it on every deploy; the other endpoints address one lens by ID. The built-in lenses (thumbnail, sm, md, lg, xl and 2xl) are reserved identifiers that every project already has; creating a lens with one returns 409 lens/identifier-reserved.

Guide: Lenses and transforms.

Endpoints

EndpointDescription
PUT /projects/:projectId/lensesCreate each lens, or change it to the definition sent, by identifier.
GET /projects/:projectId/lensesList a page of the project's lenses, newest first.
POST /projects/:projectId/lensesCreate a lens.
GET /lenses/:lensIdGet one of the project's lenses by ID
PATCH /lenses/:lensIdChange a lens's name, description, type, transform or whether the CDN serves it.
DELETE /lenses/:lensIdDelete a lens.

The lens object

Lens
idstring
Unique lens ID
identifierstring
Name used in CDN URLs after @. Lowercase letters, numbers and hyphens, at most 50 characters.
namestring
Display name
typeLensType
Asset type the lens applies to
Allowed values
imagevideoaudiodocumentwebsite
activeboolean
Whether the CDN serves the lens
createdAtnumber
When the lens was created, in milliseconds since the Unix epoch
projectIdstring (optional)
ID of the project that owns the lens; null for built-in lenses
descriptionstring (optional)
Optional description of what the lens produces
transformrecord (optional)
Image transform options, such as width and format, applied in one pass to produce the derived asset
updatedAtnumber (optional)
When the lens was last updated, in milliseconds since the Unix epoch

Endpoint details

Ensure Lenses

Create each lens, or change it to the definition sent, by identifier. An unchanged lens is returned as it is, so applications can send their lenses every time they start.

OpenAPI YAML
PUT
https://api.calmlens.com/v1/projects/
/lenses
const response = await client.ensureLenses({
  "lenses": [
    {
      "identifier": "card",
      "name": "Card",
      "type": "image",
      "active": true,
      "transform": {
        "fit": "scale-down",
        "width": 640,
        "format": "webp"
      }
    }
  ]
});

Request Body

Edit any value to update the generated request examples.


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.
409lens/identifier-reserved
The identifier belongs to a built-in lens (thumbnail, sm, md, lg, xl or 2xl). Give the lens another identifier.
500server/internal-error
An internal error occurred. Retry later, and quote requestId to support.

List Lenses

List a page of the project's lenses, newest first. The built-in lenses are always available and aren't listed.

OpenAPI YAML
GET
https://api.calmlens.com/v1/projects/
/lenses
const response = await client.lenses.list({
  "sort": "-createdAt"
});

Query Parameters

Edit any value to update the generated request examples.

string (optional)
The previous page’s nextCursor; omit for the first page
number (optional)
Items per page, 1 to 100 (default 50)
string (optional)
Sort order: a comma-separated list of fields from createdAt, id, each ascending unless prefixed with -. The default is -createdAt. An id tie-breaker in the first field's direction is added.

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.
404project/not-found
Project not found
400cursor/invalid
The cursor is invalid or belongs to a different query.
500server/internal-error
An internal error occurred. Retry later, and quote requestId to support.

Create Lens

Create a lens. Its identifier must be new to the project.

OpenAPI YAML
POST
https://api.calmlens.com/v1/projects/
/lenses
const response = await client.lenses.create({
  "identifier": "card",
  "name": "Card",
  "type": "image",
  "active": true,
  "transform": {
    "fit": "scale-down",
    "width": 640,
    "format": "webp"
  }
});

Request Body

Edit any value to update the generated request examples.

string
Name used in CDN URLs after @. Lowercase letters, numbers and hyphens, at most 50 characters.
string
Display name
LensType
Asset type the lens applies to
Allowed values
imagevideoaudiodocumentwebsite
boolean
Whether the CDN serves the lens
string (optional)
Optional description of what the lens produces
record (optional)
Image transform options, such as width and format, applied in one pass to produce the derived asset

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.
404project/not-found
Project not found
409lens/identifier-reserved
The identifier belongs to a built-in lens (thumbnail, sm, md, lg, xl or 2xl). Give the lens another identifier.
409lens/identifier-taken
The project already has a lens with this identifier. Update that lens, or give this one another identifier.
500server/internal-error
An internal error occurred. Retry later, and quote requestId to support.

Get Lens

Get one of the project's lenses by ID

OpenAPI YAML
GET
https://api.calmlens.com/v1/lenses/
const response = await client.lenses.retrieve({
  "lensId": "lens_2Xr9Lp4Vm7Qk3Tb8Nw5C"
});

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.
404lens/not-found
Lens not found. Check the lens ID or identifier in the portal.
500server/internal-error
An internal error occurred. Retry later, and quote requestId to support.

Update Lens

Change a lens's name, description, type, transform or whether the CDN serves it. The CDN serves the new transform from then on.

OpenAPI YAML
PATCH
https://api.calmlens.com/v1/lenses/
const response = await client.lenses.update({
  "lensId": "lens_2Xr9Lp4Vm7Qk3Tb8Nw5C",
  "transform": {
    "fit": "scale-down",
    "width": 800,
    "format": "webp"
  }
});

Request Body

Edit any value to update the generated request examples.

string (optional)
string (optional)
LensType (optional)
Allowed values
imagevideoaudiodocumentwebsite
boolean (optional)
record (optional)

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.
404lens/not-found
Lens not found. Check the lens ID or identifier in the portal.
500server/internal-error
An internal error occurred. Retry later, and quote requestId to support.

Delete Lens

Delete a lens. URLs that select it stop being served; files the CDN already delivered may stay in caches until they expire.

OpenAPI YAML
DELETE
https://api.calmlens.com/v1/lenses/
const response = await client.lenses.delete({
  "lensId": "lens_2Xr9Lp4Vm7Qk3Tb8Nw5C"
});

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.
404lens/not-found
Lens not found. Check the lens ID or identifier in the portal.
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