Skip to content

Deploy API

This page describes the HTTP calls that leaf deploy makes, so that a backend can deploy a static site without the CLI. It uses the same digest-based model as Netlify’s file digest deploys and Cloudflare’s Wrangler uploads: you send a manifest of file hashes first, the server reports which blobs it does not have, and you upload only those. Nothing is uploaded for files the account already has.

To deploy a zip file or one HTML page in a single request, use the archive endpoint, POST /v1/sites/{name}/deploys/archive. It takes the file as the body, with Content-Type: application/zip or text/html, and needs an Idempotency-Key header. The server unpacks and deploys the file with the same checks and limits as the steps below. The request and its options are in Host your users’ projects. The case study Hosting your users’ sites on your own domain shows it in use.

If you run deploys from your own backend jobs, read Host your users’ projects first. It covers key scopes and site names.

The base URL is https://api.leafcloud.in. This is the default of leaf (set LEAF_API to override it).

Send the key secret as a bearer token on every call:

Authorization: Bearer <key secret>

Create a deploy key for one site with the CLI, or with POST /v1/keys:

TerminalTerminal windowbash
leaf keys create --name "deployer" --can deploy --site acme-landing --expires 90d

The account must be active. An account that is not active yet gets a 403 error on the calls that create or change a deploy or a site.

A key with --site is only accepted for that site. A key without --site covers every site on the account.

CallScope
POST /v1/sites (create a site)manage. No --site restriction is allowed.
GET /v1/sites/{name}read or deploy, for that site.
GET /v1/sites/{name}/deploysread or deploy, for that site.
POST /v1/sites/{name}/deploysdeploy, for that site.
PUT /v1/deploys/{id}/blobs/{sha256}deploy.
GET and PUT /v1/deploys/{id}/blobs/{sha256}/parts... and POST .../completedeploy.
POST /v1/deploys/{id}/finalizedeploy.
POST /v1/sites/{name}/rollbackdeploy.

A deploy key cannot create or delete sites. Use a separate manage key for that job.

These limits come from the server. Per-account limits (site count, file count, space for kept deploys, deploys per day) also apply. See Pricing and limits.

LimitValue
Files per deploy1 to 5000
Size of one file25 MiB (26,214,400 bytes)
Part size for large files8 MiB (8,388,608 bytes). Files larger than this use parts.
Upload windowA deploy created more than 1 hour ago gets 410 deploy_expired on single blob uploads. Start a new deploy.
Abandoned deploysA deploy still uploading 30 minutes after creation is marked abandoned the next time its account creates a deploy.

File paths are relative keys with no leading slash, such as index.html or assets/app.css. The server checks each key by prefixing it with / and normalizing it. A key that changes under normalization, or that names a directory, gets 400 invalid_path.

POST /v1/sites/{name}/deploys/archive takes one file as the whole body: a zip with Content-Type: application/zip, or one page with text/html. It creates the site when needed and publishes the deploy in one call. It needs an Idempotency-Key header, and uses the same key rules as the manifest deploy.

Query optionMeaning
labelThe site’s label, which is the first part of its address on your project-addresses domain. Used only when the site is created; defaults to the site name. On an existing site, leave it out or pass its current label.
not_foundWhat a missing path serves. spa:<path> serves that file with status 200, so deep links reach a single-page app; page:<path> serves it with status 404, for a custom error page; index adds no fallback, so a missing path is a plain 404, and it turns off the automatic SPA fallback. The target must be in the upload.
  • Put index.html at the root of the zip, or put every file inside one top-level folder. With one folder and no root file, its contents become the site root. Two or more top-level folders are kept as they are. __MACOSX/ entries, .DS_Store files, and root Thumbs.db or desktop.ini files are ignored.
  • When index.html loads a JavaScript bundle and there is no other HTML page, the endpoint sets not_found=spa:index.html itself. A not_found query option overrides that; index turns the automatic fallback off.
  • The response adds site, created_site, unchanged, urls, files, bytes, not_found and spa to the finalized deploy. not_found is the fallback in effect.
  • A site name is unique across the whole platform. Prefix member names, for example acme-alice.
  • A bulk import should run a few uploads at a time. When every archive slot is busy the call returns 429 archive_busy with Retry-After; wait that long and retry the same upload with the same Idempotency-Key. A refused request created nothing.

See Host your users’ projects for the request in context, and Move user uploads from R2 for a bulk import from an R2 bucket.

To remove a site, send DELETE /v1/sites/{name} with {"confirm": "<name>"}. It unpublishes every address, including the label on a project-addresses domain. The name stays reserved for 30 days, and the label is free at once.

Most errors have this body:

{"error":{"code":"invalid_hash","message":"sha256 must be 64 lowercase hexadecimal characters"}}

Branch on error.code, not on the message. One exception: finalize returns 429 finalize_busy with {"error":"finalize_busy","message":"Finalize capacity is full"}, where error is a string.

Retry these after a delay. Honor Retry-After when it is present:

  • 429 upload_busy and 429 archive_busy (both sent with Retry-After) and 429 finalize_busy
  • 408 upload_timeout
  • 502, 503, and 504
  • 507 insufficient_storage
  • Network errors

Do not retry these. Fix the request, or start a new deploy:

  • Any other 400, 403, 404, 409, 410, and 422
  • 429 deploy_limit, which lasts until the daily limit resets

Check whether the site exists:

TerminalTerminal windowbash
curl -sS -H "Authorization: Bearer $LEAF_TOKEN" "$API/v1/sites/acme-landing"

A 200 response is the site. A 404 with "code":"not_found" means you must create it. Create it with a manage key:

POST /v1/sites
Content-Type: application/json
{"name": "acme-landing"}

name is optional. If you omit it, the server picks a name. The response is 201 Created:

{
"name": "acme-landing",
"url": "https://acme-landing.leafcloud.app",
"created_at": 1767225600,
"framework": null
}

Errors: 422 blocked_name (the name is reserved or not allowed), 403 site_limit, and 409 name_taken.

For each file, compute:

  • sha256: the SHA-256 of the file’s bytes, as 64 lowercase hex characters
  • size: the file’s length in bytes

Use the same bytes you upload later. A hash can appear in several files, but all of them must have the same size.

POST /v1/sites/acme-landing/deploys
Authorization: Bearer <key secret>
Idempotency-Key: 4f0c2a9e7b1d43c8a6e2f5d90b7c1e34
Content-Type: application/json
{
"files": {
"index.html": {"sha256": "<64 hex>", "size": 120},
"assets/app.css": {"sha256": "<64 hex>", "size": 4096}
},
"framework": "static HTML",
"not_found": "index"
}

Fields:

FieldRequiredMeaning
filesYesMap from path to {sha256, size}.
frameworkNoA framework name, such as static HTML, Vite, or Astro. Any name the server does not know is stored as no framework.
not_foundNoWhat to serve for a missing path. index (the default when omitted) adds no fallback, so a missing path is a plain 404; page:<path> serves that key with status 404; spa:<path> serves it with status 200. The key must be in files.

Idempotency-Key is required. It must be 1 to 200 characters. Use a fresh random value for each new deploy, and reuse the same value with the same body when you retry. Reusing a key with a different site or body gets 409 idempotency_mismatch.

The response is 200 OK for a new deploy:

{
"deploy_id": "d_9AQ3sK1mVx0Lq8rT2uYcZw",
"upload": ["<sha256 of assets/app.css>"],
"changed_files": 2,
"unchanged_files": 0,
"part_size": 8388608
}
  • upload lists the hashes the server does not have yet. Upload only these. Hashes the account already has are not listed.
  • changed_files and unchanged_files compare against the live deploy: a file counts as unchanged when its path, sha256, and size all match.
  • part_size is always present for a new deploy. It is the part size for step 4.

If the manifest is identical to the live deploy, the server does not create a deploy. The response is 200 OK:

{"unchanged": true, "deploy_id": "d_...", "upload": [], "changed_files": 0, "unchanged_files": 2}

The site already serves this content. Stop here. deploy_id is the live deploy. Do not finalize it.

Errors on this step:

StatusCodeMeaning
400idempotency_key_requiredThe header is missing or empty, or longer than 200 characters.
400too_many_filesZero files, more than 5000, or more than your account allows.
400invalid_pathA key is not a valid relative path.
400invalid_hashA sha256 is not 64 lowercase hex characters.
400file_too_largeA file is over 25 MiB or over your account’s per-file limit.
400invalid_manifestThe same hash appears with two different sizes.
400invalid_not_foundThe not_found value is not valid, or it names a key that is not in files.
400storage_quotaThe deploy would exceed your storage quota.
409idempotency_mismatchThe key was used before with a different site or body.
409idempotency_conflictThe key is already in use. Retry with a new key.
429deploy_limitThe daily deploy limit is reached.

A blob is the content of one hash. For each sha256 in upload, pick the upload method from the file’s size:

  • size is 8 MiB or less: send one PUT. See Single upload.
  • size is more than 8 MiB: send it in parts. See Parts.

Blobs can upload in parallel. The leaf CLI uses four at a time.

PUT /v1/deploys/d_9AQ3sK1mVx0Lq8rT2uYcZw/blobs/<sha256>
Authorization: Bearer <key secret>
<raw file bytes>

The body is the raw file bytes. There is no JSON wrapper. The response is 204 No Content.

The server checks the bytes against the declared size and hash. Errors:

StatusCodeMeaning
400hash_mismatchThe bytes do not hash to the sha256 in the URL.
400body_size_mismatchThe body is shorter than the declared size.
400body_too_largeThe body is longer than the declared size.
400invalid_hashThe URL’s hash is not valid.
403forbiddenThe hash is not in this deploy’s manifest.
404not_foundNo such deploy.
409deploy_not_uploadingThe deploy is no longer uploading. Start a new deploy.
410deploy_expiredThe deploy is more than 1 hour old. Start a new deploy.
408upload_timeoutThe body was not sent in time. Retry.
429upload_busyToo many uploads are running. Retry after Retry-After.
507insufficient_storageThe service is full. Retry later.

Use parts for any file over 8 MiB. Parts let you retry one piece at a time.

a. List the parts already stored. Use this to resume an interrupted upload:

GET /v1/deploys/<deploy_id>/blobs/<sha256>/parts
{"parts": [0, 1]}

b. Upload each part you do not have. Part numbers start at 0. For a file of size bytes, there are count = ceil(size / 8388608) parts. Every part except the last is exactly 8,388,608 bytes. The last part holds the rest.

PUT /v1/deploys/<deploy_id>/blobs/<sha256>/parts/<n>
Authorization: Bearer <key secret>
x-part-sha256: <sha256 of this part's bytes, lowercase hex>
<part bytes>

The response is 204 No Content. The server rejects a part whose bytes do not match x-part-sha256 (400 hash_mismatch). It also rejects a part with the wrong length (400 body_size_mismatch), a part body over 8 MiB (413 body_too_large), and a part number out of range (400 invalid_part). A part is also rejected with 400 invalid_part when the file is 8 MiB or less, which must use a single upload. Missing or empty x-part-sha256 gets 400 missing_part_hash.

c. Complete the blob. Send the part count:

POST /v1/deploys/<deploy_id>/blobs/<sha256>/complete
Content-Type: application/json
{"parts": 4}

The server joins the parts and checks the result against sha256. The response is 204 No Content. Errors:

StatusCodeMeaning
400invalid_partsparts does not equal count.
400missing_partsOne or more parts were not uploaded. Upload them, then complete again.
400hash_mismatchThe joined bytes do not match sha256. Re-upload the file’s parts.
409deploy_not_uploadingThe deploy is no longer uploading.
507insufficient_storageThe service is full. Retry later.
POST /v1/deploys/<deploy_id>/finalize
Authorization: Bearer <key secret>
Content-Type: application/json
{}

Finalizing checks that every file is present, then publishes the deploy. Responses:

  • 200 OK, published:

    {
    "deploy_id": "d_9AQ3sK1mVx0Lq8rT2uYcZw",
    "url": "https://acme-landing.leafcloud.app",
    "files": 2,
    "uploaded_bytes": 4216,
    "total_bytes": 4216,
    "duration_ms": 412,
    "status": "live",
    "propagation": {"edges_total": 2, "edges_live": 1, "pending": [{"edge": "edge-a", "applied_version": 7}]}
    }

    propagation is either the edge counts above, or {"state": "unknown"} when the server has no edge report yet. pending lists the edges that do not have the new version yet. To wait for them, poll the history call in step 6 until propagation shows no pending edges. The CLI waits up to 30 seconds by default.

  • 200 OK with "status": "live", already live: the deploy was published before. The body has deploy_id, status, url, and propagation.

  • 202 Accepted, still finalizing: another finalize is running. The body is {"deploy_id": "...", "status": "finalizing"}, and the response has Retry-After: 1. POST again after the delay.

Errors:

StatusCodeMeaning
400missing_blobsSome blobs are missing. The message lists up to 10 hashes, comma separated. Upload them, then finalize again.
400publish_failedPublishing failed. The message says why. Start a new deploy.
403quota_exceededThe deploy would exceed your storage quota.
409deploy_not_uploadingThe deploy is no longer uploading. Start a new deploy.
409stale_finalizeA newer deploy is already live. Start a new deploy from the current files.
429finalize_busyFinalize capacity is full. Retry after Retry-After.
500publish_failedPublishing failed on the server. Retry, or start a new deploy.

List the site’s deploys, newest first:

TerminalTerminal windowbash
curl -sS -H "Authorization: Bearer $LEAF_TOKEN" "$API/v1/sites/acme-landing/deploys"

Each item:

{
"deploy_id": "d_9AQ3sK1mVx0Lq8rT2uYcZw",
"status": "live",
"created_at": 1767225600,
"last_activity_at": 1767225650,
"error": null,
"files": 2,
"planned_files": 2,
"uploaded_files": 2,
"bytes": 4216,
"total_bytes": 4216,
"planned_bytes": 4216,
"propagation": {"edges_total": 2, "edges_live": 2, "pending": []}
}

status is one of uploading, interrupted (no activity for 2 minutes or more), abandoned (no activity for more than 30 minutes), ready (a finalized deploy that is not live), live, failed (see error), or pruned (removed by retention). files, bytes, and total_bytes appear only for live and ready deploys. propagation appears only for live deploys. created_at and last_activity_at are Unix seconds.

To roll back, POST to the rollback endpoint. The body is optional:

TerminalTerminal windowbash
curl -sS -H "Authorization: Bearer $LEAF_TOKEN" -H 'Content-Type: application/json' \
-X POST "$API/v1/sites/acme-landing/rollback" -d '{"deploy_id":"d_9AQ3sK1mVx0Lq8rT2uYcZw"}'

Without deploy_id, the server rolls back to the most recent ready or superseded deploy. The response is 200 OK:

{"deploy_id": "d_9AQ3sK1mVx0Lq8rT2uYcZw", "url": "https://acme-landing.leafcloud.app", "status": "live"}

Errors:

StatusCodeMeaning
404not_foundNo such site.
404deploy_not_foundThe deploy is not one of the kept deploys for this site, or there is no deploy to roll back to.
409deploy_not_finalizedThe target deploy never finished uploading.
500internalRollback failed. Retry.
StepCallScopeSuccessNext step
1GET /v1/sites/{name}; POST /v1/sites if missingread or deploy; manage to create200; 2012
2(local)nonenone3
3POST /v1/sites/{name}/deploys with Idempotency-Keydeploy200 with deploy_id and upload4, or stop if unchanged
4PUT .../blobs/{sha256} (8 MiB or less)deploy2045
4GET .../parts, PUT .../parts/{n}, POST .../complete (over 8 MiB)deploy204 each5
5POST /v1/deploys/{id}/finalizedeploy200 with status: live; 202 means poll again6
6GET /v1/sites/{name}/deploys; POST /v1/sites/{name}/rollbackread or deploy; deploy200done

This script deploys a two-file site with curl, sha256sum, stat, and jq. It creates the site if needed, then runs steps 3 to 5. It writes its sample files to a new temporary folder.

Set LEAF_TOKEN to a deploy key for the site. If the site does not exist yet, also set MANAGE_TOKEN to a manage key. A deploy key cannot create sites, and a manage key cannot deploy, so the script uses one key for each step.

#!/usr/bin/env bash
set -euo pipefail
API="${LEAF_API:-https://api.leafcloud.in}"
SITE="${SITE:-acme-landing}"
: "${LEAF_TOKEN:?set LEAF_TOKEN to a deploy key for $SITE}"
AUTH=(-H "Authorization: Bearer $LEAF_TOKEN")
JSON=(-H 'Content-Type: application/json')
# A two-file site.
SRC="$(mktemp -d)"
mkdir -p "$SRC/assets"
printf '<!doctype html><title>Hello</title><link rel="stylesheet" href="assets/app.css"><h1>Hello</h1>\n' > "$SRC/index.html"
printf 'body { font-family: sans-serif; }\n' > "$SRC/assets/app.css"
PATHS=(index.html assets/app.css)
# 1. Create the site if it does not exist. Only a manage key can create a site,
# so the script needs MANAGE_TOKEN for that one call.
if ! curl -fsS "${AUTH[@]}" "$API/v1/sites/$SITE" >/dev/null 2>&1; then
: "${MANAGE_TOKEN:?the site does not exist yet: set MANAGE_TOKEN to a manage key}"
curl -fsS -H "Authorization: Bearer $MANAGE_TOKEN" "${JSON[@]}" -X POST "$API/v1/sites" -d "{\"name\":\"$SITE\"}" >/dev/null
fi
# 2. Build the manifest: sha256 and size for each file.
FILES='{}'
for path in "${PATHS[@]}"; do
sha=$(sha256sum "$SRC/$path" | cut -d' ' -f1)
size=$(stat -c %s "$SRC/$path")
FILES=$(jq --arg p "$path" --arg h "$sha" --argjson s "$size" \
'. + {($p): {sha256: $h, size: $s}}' <<<"$FILES")
done
BODY=$(jq -n --argjson files "$FILES" '{files: $files, not_found: "index"}')
# 3. Create the deploy. The idempotency key stays the same for every retry of this body.
IDEM=$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')
CREATED=$(curl -fsS "${AUTH[@]}" "${JSON[@]}" -H "Idempotency-Key: $IDEM" \
-X POST "$API/v1/sites/$SITE/deploys" -d "$BODY")
DEPLOY_ID=$(jq -r '.deploy_id' <<<"$CREATED")
echo "deploy: $DEPLOY_ID"
if [ "$(jq -r '.unchanged // false' <<<"$CREATED")" = "true" ]; then
echo "unchanged: the site already serves these files"
exit 0
fi
# 4. Upload each blob the server is missing. Both files are under 8 MiB,
# so each one is a single PUT. Larger files need the parts flow.
for sha in $(jq -r '.upload[]' <<<"$CREATED"); do
path=$(jq -r --arg h "$sha" 'to_entries[] | select(.value.sha256 == $h) | .key' <<<"$FILES" | head -n1)
curl -fsS "${AUTH[@]}" --data-binary "@$SRC/$path" \
-X PUT "$API/v1/deploys/$DEPLOY_ID/blobs/$sha"
echo "uploaded $path"
done
# 5. Finalize. A 202 means another finalize is running: wait and try again.
RESP=$(mktemp)
while :; do
CODE=$(curl -sS "${AUTH[@]}" "${JSON[@]}" -o "$RESP" -w '%{http_code}' \
-X POST "$API/v1/deploys/$DEPLOY_ID/finalize" -d '{}')
case "$CODE" in
200) break ;;
202) sleep 1 ;;
*) echo "finalize failed (HTTP $CODE):" >&2; cat "$RESP" >&2; exit 1 ;;
esac
done
jq '{url, status, files, uploaded_bytes}' "$RESP"

Expected output, with the placeholders filled in:

deploy: d_9AQ3sK1mVx0Lq8rT2uYcZw
uploaded assets/app.css
uploaded index.html
{
"url": "https://acme-landing.leafcloud.app",
"status": "live",
"files": 2,
"uploaded_bytes": 129
}

The uploads print in hash order, which is fixed for these two files. A second run with the same files prints unchanged: the site already serves these files and exits without uploading.

The script prints the error body when finalize fails. The -f flag on the create and upload calls hides the body on error. Remove it from a call to see the body while you debug.