Generate experiences with Puck AI
Read docs
CloudServer APIs

Server APIs

Puck Cloud provides server APIs for using its modules from your backend.

Node

Create a client

To use the modules, create a client:

import puckCloud from "@puckeditor/cloud-client";
 
const puck = puckCloud();

The client reads your API key from the PUCK_API_KEY environment variable. To pass a different key, set apiKey.

Call an API

Call one of the available APIs on the client:

const page = await puck.pages.getPublished("/about");

Handle errors

The client throws a PuckCloudError when Puck Cloud refuses or fails a request. Handle this in a try-catch:

import { PuckCloudError } from "@puckeditor/cloud-client";
 
try {
  await puck.pages.create({ path: "/about" });
} catch (error) {
  if (error instanceof PuckCloudError && error.statusCode === 400) {
    // Handle error
  }
}

HTTP

Every API is also available over HTTP, but the HTTP API isn’t documented yet.

Available APIs

APIs are namespaced by resource.

ResourceDescription
aiGenerate pages
authManage the user’s session
pagesManage pages

Further reading