Skip to main content
This page documents @squarecloud/api v6, a rewrite of the SDK. Coming from v5? Read the v5 → v6 migration guide.

Requirements

  • Node.js 22 or newer, Deno, Bun or an edge runtime. The SDK only needs fetch, FormData, Blob and web streams.
  • An API key (see API key and scopes).
The package ships ESM and CommonJS builds, has no runtime dependencies and includes its own TypeScript types: you no longer need @squarecloud/api-types.

Installation

API key and scopes

Create a key at squarecloud.app/account/security. The SDK sends it as-is in the Authorization header (no Bearer prefix). A key can be limited to scopes (apps:read, apps:deploy, apps:control, ai:chat, …) and to specific apps or databases:
  • A call outside those limits throws a SquareCloudAPIError with 403 MISSING_SCOPE or RESOURCE_NOT_ALLOWED.
  • List methods (account.me(), apps.statusAll(), …) only return the resources the key can see.
  • An unknown, revoked or expired key is 401 ACCESS_DENIED.
Keep the key on the server. The SDK runs in a browser too, but that would expose the key to every visitor.
The examples read the key from the SQUARECLOUD_API_KEY environment variable. Set it in the terminal where you run them:

Creating the client

The first example prints your account name and the number of apps the key can see:
An empty or whitespace-only key throws a TypeError in the constructor, before any request.

Options

The API key is stored as a regular property of the client object. Don’t console.log or serialize the client.

Modules

The only runtime exports are SquareCloudAPI, SquareCloudAPIError and BASE_URL. Every other export (App, RuntimeStats, ErrorCode, …) is a type:

Conventions

Ids first, plain data back

Every method takes the resource id as its first argument and returns plain data (no classes, no cache). Field names are the API’s own (created_at, version_id, lastModified, joinedAt, netIO, …), so the API reference applies as-is.
  • Mutations resolve to void, unless the API returns data (envs.*, deploys.setWebhook, deploys.linkGithubApp, databases.resetCredentials and the create methods).
  • A string result is never undefined: it is "" when the API sends none.
  • Lists come complete in one call: there is no pagination.
Methods are arrow functions, so you can destructure them:

Workspace apps

Every appId also accepts the composite form <appId>-<workspaceId> to act on an app shared with you through a workspace. workspaces.get() and workspaces.list() return raw ids; you build the composite id yourself:

Ids are encoded

Ids in the URL path are percent-encoded. An id that is empty, . or .. would reach a different route, so it fails locally with INVALID_ID (status 0) before anything is sent. Workspace routes send their ids in the body instead: there, INVALID_ID (400) comes from the server.

Dates

start and end arguments (see Network) take an ISO 8601 string or a Date. Dates in responses stay as the API sends them (ISO strings, or Unix milliseconds where the API uses them).

Timeouts

A timeoutMs of 0 or less, Infinity or >= 2^31 disables every timeout, the 120 s floors included. Only five methods take an AbortSignal: apps.create, apps.commit, files.write, apps.realtime and downloadSnapshot.
An aborted call rejects with the signal’s reason, not with a SquareCloudAPIError. An aborted realtime() loop just ends.

Account

api.account.me() returns the authenticated user plus the apps and databases the key can see.
api.account.snapshots({ scope }) lists every snapshot of the account: see Snapshots.

Platform status

api.service.status() returns the public platform status. The route needs no valid key, but the client still requires a non-empty one.
unknown means the check itself could not run: it is not evidence of an outage.

Next steps

Managing applications

Status, lifecycle, logs and metrics.

Errors

Error class, retries and rate limits.

API introduction

Base URL, authentication and a first request.

CLI quickstart

Deploy and manage apps from the terminal.