Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt

Use this file to discover all available pages before exploring further.

The network module is only available on website applications. Narrow the type with app.isWebsite() first:
const app = await api.applications.fetch("abc123def456abc123def456");

if (!app.isWebsite()) {
    throw new Error("This application is not a website");
}

app.network; // NetworkModule

Custom domain

app.network.setCustomDomain(domain) sets or removes the custom domain bound to the website.
await app.network.setCustomDomain("yoursite.com");

// Pass "@" to remove the configured custom domain
await app.network.setCustomDomain("@");
Custom domains require a Senior plan or higher.

DNS records

After attaching a custom domain you need to configure DNS at your registrar. app.network.dns() returns the ownership record and SSL status.
const dns = await app.network.dns();

console.log(`${dns.ownership.type} ${dns.ownership.name}${dns.ownership.value}`);
console.log(`SSL: ${dns.ssl.status}`); // "pending" | "pending_validation" | "active"
The shape changed in v4. app.network.dns() previously returned an array of records — it now returns a single object: { ownership, ssl }.

Analytics

app.network.analytics({ start, end }) returns aggregated edge analytics. start and end accept either ISO 8601 strings or Date objects. Maximum retention window is 7 days.
const since = new Date(Date.now() - 24 * 60 * 60 * 1000);

const analytics = await app.network.analytics({
    start: since,
    end: new Date(),
});

if ("visits" in analytics) {
    console.log(analytics.visits.length, "time buckets");
    console.log("Top countries:", analytics.countries.slice(0, 5));
    console.log("Top paths:",     analytics.paths.slice(0, 5));
}
For empty windows (e.g. before the app was created) the API returns {}. Guard with "visits" in analytics before reading.
v3 called this endpoint with no arguments. v4 requires { start, end }.

Error tracking

app.network.errors({ start, end, include4xx? }) returns the edge error breakdown. By default only 5xx errors are included.
const errors = await app.network.errors({
    start: since,
    end: new Date(),
    include4xx: true, // include 4xx alongside 5xx
});

if ("summary" in errors) {
    console.log(`Total: ${errors.summary.total}`);
    console.log("By class:",          errors.summary.by_class);
    console.log("Top failing paths:", errors.top_paths.slice(0, 3));
}

Per-request logs

app.network.logs({ start, end }) returns the per-request edge logs.
const logs = await app.network.logs({ start: since, end: new Date() });

for (const log of logs.slice(0, 5)) {
    console.log(
        log.timestamp,
        log.request.method, log.request.path,
        "→",
        log.response.status,
        `(${log.client.country ?? "??"})`,
    );
}
Per-request logs require a Pro plan or higher.

Latency percentiles

app.network.performance({ start, end }) returns p50 / p95 / p99 latencies for the edge and origin layers.
const perf = await app.network.performance({ start: since, end: new Date() });

if ("summary" in perf) {
    const { p50, p95, p99 } = perf.summary.edge;
    console.log(`Edge p50/p95/p99: ${p50}/${p95}/${p99}ms`);
    console.log("Slowest paths:", perf.slowest_paths.slice(0, 3));
}
Performance metrics require a Pro plan or higher.

Purging the edge cache

app.network.purgeCache() invalidates the entire edge cache for the application’s domains.
await app.network.purgeCache();
In v3 (and the short-lived v4.0.0) purgeCache(paths?) accepted a list of paths to purge selectively. Starting with v4.0.1 the argument was removed — calling purgeCache() always purges the entire cache.