This page documents
github.com/squarecloudofc/sdk-api-go/v3 (v3.0.0), a rewrite of the SDK. Coming from v2? Read the v2 → v3 migration guide.Requirements
- Go 1.22 or newer.
- An API key (see API key and scopes).
squarecloud.
Installation
API key and scopes
Create a key at squarecloud.app/account/security. The SDK sends it as-is in theAuthorization 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 returns an
*APIErrorwith 403MISSING_SCOPEorRESOURCE_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.
SQUARECLOUD_API_KEY environment variable. Set it in the terminal where you run them:
- macOS / Linux
- Windows (PowerShell)
Creating the client
main.go in a module (go mod init example.com/hello, then the go get above) and run go run .. It prints your account name and the number of apps the key can see:
squarecloud.New(apiKey, opts...) returns a *Client and never an error. A *Client is safe for concurrent use: build it once and share it between goroutines.
Because New cannot fail, an empty or whitespace-only key is not rejected there. Instead, every call except Service.Status fails locally with INVALID_API_KEY (status 0) before any request. This code exists only in the Go SDK.
Options
Pass options toNew after the key:
The SDK never logs. To trace requests, wrap the
http.RoundTripper of the client you pass to WithHTTPClient.
Running the examples
The snippets on the Go SDK pages are fragments. Each one runs on its own inside this program, which declares thectx, c and appID they use:
main, then run goimports -w . to add the imports it needs (fmt, log, time, …). Install it with go install golang.org/x/tools/cmd/goimports@latest, or let your editor’s Go extension (gopls) add imports on save. Pages that need other ids, such as a database or a workspace, start with their own version of this program.
Modules
Besides
New and the With* options, the package exports the DefaultBaseURL and Version constants, the APIError type with one Code* constant per error code, typed constants for enumerated inputs (DatabaseRedis, GroupView, ResetPassword, SnapshotScopeDatabases, …) and one struct per API shape, which you can use in your own code:
Conventions
Context and ids first, typed data back
Every method takes acontext.Context first and the resource id next, and returns plain structs (no methods, no cache). The json tags are the API’s own field names (created_at, version_id, lastModified, joinedAt, netIO, …), so the API reference applies as-is: CreatedAt is created_at, VersionID is version_id. Fields the API adds later are ignored, so they never break decoding.
- Mutations return only an
error, unless the API returns data (Envs.*,Deploys.SetWebhook,Deploys.LinkGithubApp,Databases.ResetCredentialsand theCreatemethods). - A string result is
""when the API sends none. - Fields the API may send as
nullare pointers: check them fornilbefore use. - Counters and byte sizes are
int64. - Lists come complete in one call: there is no pagination.
Workspace apps
EveryappID 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) are time.Time values, sent as RFC 3339 in UTC (whole seconds). In responses, the API’s ISO 8601 strings decode to time.Time, and the fields the API sends as Unix milliseconds stay numbers (Plan.Duration and Uptime as *int64, FileEntry.LastModified as *float64): convert them with time.UnixMilli.
Timeouts
- The default deadline applies only when
ctxhas no deadline. A deadline onctxalways wins, shorter or longer than the default, floors included. - One deadline covers the whole call: every attempt and the waits between retries.
WithTimeout(0)(or anyd <= 0) disables every default deadline, the 2-minute floors included.
ctx, so you can bound or cancel any call:
ctx expires returns an *APIError with TIMEOUT, and one whose ctx is canceled returns NETWORK_ERROR, both with status 0. They unwrap to the context’s error, so errors.Is(err, context.DeadlineExceeded) and errors.Is(err, context.Canceled) work. A realtime loop returns the bare ctx.Err() instead.
Account
c.Account.Me(ctx) returns the authenticated user plus the apps and databases the key can see.
c.Account.Snapshots(ctx, scope) lists every snapshot of the account: see Snapshots.
Platform status
c.Service.Status(ctx) returns the public platform status. The route needs no key, and it is the only method that also works on a client built with an empty key.
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.

