Generate experiences with Puck AI
Read docs
CloudAPI referencecloud-clientpuckCloud

puckCloud

Create a Puck Cloud client. Its requests use the API key, host and auth given here.

import puckCloud from "@puckeditor/cloud-client";
// or: const puckCloud = require("@puckeditor/cloud-client");
 
const puck = puckCloud(process.env.PUCK_API_KEY);
const page = await puck.pages.get("page_123");

Returns a client.

Args

ParamExampleTypeStatus
config"SECRET"String | Object-

config

An API key, or the API key, host and auth to use, as options.

Options

ParamExampleTypeStatus
apiKeyapiKey: "SECRET"String-
authauth: { tenantId: "team-1" }Object-
hosthost: "https://www.example.com/api"String-

apiKey

The API key to send with each request. Defaults to the PUCK_API_KEY environment variable.

const puck = puckCloud({
  apiKey: process.env.MY_PUCK_KEY,
});

auth

The tenant to use, and the user to attribute changes to. Takes the same tenantId and identity as puckHandler.

const puck = puckCloud({
  auth: {
    tenantId: user.teamId,
    identity: { id: user.id, name: user.name },
  },
});

host

The Puck Cloud host to call. Defaults to the PUCK_HOST environment variable, then Puck Cloud.

const puck = puckCloud({
  host: "https://www.example.com/api",
});

Returns

Returns an object with the server APIs for each module:

ParamExampleType
aiai: { generate: () => {} }Object
authauth: { getSession: () => {} }Object
pagespages: { list: () => {} }Object