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.
Base URL and authentication
Section titled “Base URL and authentication”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:
leaf keys create --name "deployer" --can deploy --site acme-landing --expires 90dThe 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.
Which scope each call needs
Section titled “Which scope each call needs”A key with --site is only accepted for that site. A key without --site covers every site on the account.
| Call | Scope |
|---|---|
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}/deploys | read or deploy, for that site. |
POST /v1/sites/{name}/deploys | deploy, for that site. |
PUT /v1/deploys/{id}/blobs/{sha256} | deploy. |
GET and PUT /v1/deploys/{id}/blobs/{sha256}/parts... and POST .../complete | deploy. |
POST /v1/deploys/{id}/finalize | deploy. |
POST /v1/sites/{name}/rollback | deploy. |
A deploy key cannot create or delete sites. Use a separate manage key for that job.
Limits
Section titled “Limits”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.
| Limit | Value |
|---|---|
| Files per deploy | 1 to 5000 |
| Size of one file | 25 MiB (26,214,400 bytes) |
| Part size for large files | 8 MiB (8,388,608 bytes). Files larger than this use parts. |
| Upload window | A deploy created more than 1 hour ago gets 410 deploy_expired on single blob uploads. Start a new deploy. |
| Abandoned deploys | A 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.
Archive deploys
Section titled “Archive deploys”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 option | Meaning |
|---|---|
label | The 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_found | What 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.htmlat 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_Storefiles, and rootThumbs.dbordesktop.inifiles are ignored. - When
index.htmlloads a JavaScript bundle and there is no other HTML page, the endpoint setsnot_found=spa:index.htmlitself. Anot_foundquery option overrides that;indexturns the automatic fallback off. - The response adds
site,created_site,unchanged,urls,files,bytes,not_foundandspato the finalized deploy.not_foundis 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_busywithRetry-After; wait that long and retry the same upload with the sameIdempotency-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.
Errors
Section titled “Errors”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_busyand429 archive_busy(both sent withRetry-After) and429 finalize_busy408 upload_timeout502,503, and504507 insufficient_storage- Network errors
Do not retry these. Fix the request, or start a new deploy:
- Any other
400,403,404,409,410, and422 429 deploy_limit, which lasts until the daily limit resets
The steps
Section titled “The steps”1. Make sure the site exists
Section titled “1. Make sure the site exists”Check whether the site exists:
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/sitesContent-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.
2. Hash the files and build the manifest
Section titled “2. Hash the files and build the manifest”For each file, compute:
sha256: the SHA-256 of the file’s bytes, as 64 lowercase hex characterssize: 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.
3. Create the deploy
Section titled “3. Create the deploy”POST /v1/sites/acme-landing/deploysAuthorization: Bearer <key secret>Idempotency-Key: 4f0c2a9e7b1d43c8a6e2f5d90b7c1e34Content-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:
| Field | Required | Meaning |
|---|---|---|
files | Yes | Map from path to {sha256, size}. |
framework | No | A framework name, such as static HTML, Vite, or Astro. Any name the server does not know is stored as no framework. |
not_found | No | What 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}uploadlists the hashes the server does not have yet. Upload only these. Hashes the account already has are not listed.changed_filesandunchanged_filescompare against the live deploy: a file counts as unchanged when its path,sha256, andsizeall match.part_sizeis 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:
| Status | Code | Meaning |
|---|---|---|
| 400 | idempotency_key_required | The header is missing or empty, or longer than 200 characters. |
| 400 | too_many_files | Zero files, more than 5000, or more than your account allows. |
| 400 | invalid_path | A key is not a valid relative path. |
| 400 | invalid_hash | A sha256 is not 64 lowercase hex characters. |
| 400 | file_too_large | A file is over 25 MiB or over your account’s per-file limit. |
| 400 | invalid_manifest | The same hash appears with two different sizes. |
| 400 | invalid_not_found | The not_found value is not valid, or it names a key that is not in files. |
| 400 | storage_quota | The deploy would exceed your storage quota. |
| 409 | idempotency_mismatch | The key was used before with a different site or body. |
| 409 | idempotency_conflict | The key is already in use. Retry with a new key. |
| 429 | deploy_limit | The daily deploy limit is reached. |
4. Upload the missing blobs
Section titled “4. Upload the missing blobs”A blob is the content of one hash. For each sha256 in upload, pick the upload method from the file’s size:
sizeis 8 MiB or less: send onePUT. See Single upload.sizeis more than 8 MiB: send it in parts. See Parts.
Blobs can upload in parallel. The leaf CLI uses four at a time.
Single upload
Section titled “Single upload”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:
| Status | Code | Meaning |
|---|---|---|
| 400 | hash_mismatch | The bytes do not hash to the sha256 in the URL. |
| 400 | body_size_mismatch | The body is shorter than the declared size. |
| 400 | body_too_large | The body is longer than the declared size. |
| 400 | invalid_hash | The URL’s hash is not valid. |
| 403 | forbidden | The hash is not in this deploy’s manifest. |
| 404 | not_found | No such deploy. |
| 409 | deploy_not_uploading | The deploy is no longer uploading. Start a new deploy. |
| 410 | deploy_expired | The deploy is more than 1 hour old. Start a new deploy. |
| 408 | upload_timeout | The body was not sent in time. Retry. |
| 429 | upload_busy | Too many uploads are running. Retry after Retry-After. |
| 507 | insufficient_storage | The service is full. Retry later. |
Parts for large files
Section titled “Parts for large files”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>/completeContent-Type: application/json
{"parts": 4}The server joins the parts and checks the result against sha256. The response is 204 No Content. Errors:
| Status | Code | Meaning |
|---|---|---|
| 400 | invalid_parts | parts does not equal count. |
| 400 | missing_parts | One or more parts were not uploaded. Upload them, then complete again. |
| 400 | hash_mismatch | The joined bytes do not match sha256. Re-upload the file’s parts. |
| 409 | deploy_not_uploading | The deploy is no longer uploading. |
| 507 | insufficient_storage | The service is full. Retry later. |
5. Finalize
Section titled “5. Finalize”POST /v1/deploys/<deploy_id>/finalizeAuthorization: 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}]}}propagationis either the edge counts above, or{"state": "unknown"}when the server has no edge report yet.pendinglists the edges that do not have the new version yet. To wait for them, poll the history call in step 6 untilpropagationshows no pending edges. The CLI waits up to 30 seconds by default. -
200 OKwith"status": "live", already live: the deploy was published before. The body hasdeploy_id,status,url, andpropagation. -
202 Accepted, still finalizing: another finalize is running. The body is{"deploy_id": "...", "status": "finalizing"}, and the response hasRetry-After: 1. POST again after the delay.
Errors:
| Status | Code | Meaning |
|---|---|---|
| 400 | missing_blobs | Some blobs are missing. The message lists up to 10 hashes, comma separated. Upload them, then finalize again. |
| 400 | publish_failed | Publishing failed. The message says why. Start a new deploy. |
| 403 | quota_exceeded | The deploy would exceed your storage quota. |
| 409 | deploy_not_uploading | The deploy is no longer uploading. Start a new deploy. |
| 409 | stale_finalize | A newer deploy is already live. Start a new deploy from the current files. |
| 429 | finalize_busy | Finalize capacity is full. Retry after Retry-After. |
| 500 | publish_failed | Publishing failed on the server. Retry, or start a new deploy. |
6. Check history and roll back
Section titled “6. Check history and roll back”List the site’s deploys, newest first:
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:
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:
| Status | Code | Meaning |
|---|---|---|
| 404 | not_found | No such site. |
| 404 | deploy_not_found | The deploy is not one of the kept deploys for this site, or there is no deploy to roll back to. |
| 409 | deploy_not_finalized | The target deploy never finished uploading. |
| 500 | internal | Rollback failed. Retry. |
Summary
Section titled “Summary”| Step | Call | Scope | Success | Next step |
|---|---|---|---|---|
| 1 | GET /v1/sites/{name}; POST /v1/sites if missing | read or deploy; manage to create | 200; 201 | 2 |
| 2 | (local) | none | none | 3 |
| 3 | POST /v1/sites/{name}/deploys with Idempotency-Key | deploy | 200 with deploy_id and upload | 4, or stop if unchanged |
| 4 | PUT .../blobs/{sha256} (8 MiB or less) | deploy | 204 | 5 |
| 4 | GET .../parts, PUT .../parts/{n}, POST .../complete (over 8 MiB) | deploy | 204 each | 5 |
| 5 | POST /v1/deploys/{id}/finalize | deploy | 200 with status: live; 202 means poll again | 6 |
| 6 | GET /v1/sites/{name}/deploys; POST /v1/sites/{name}/rollback | read or deploy; deploy | 200 | done |
Worked example
Section titled “Worked example”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 bashset -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/nullfi
# 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")doneBODY=$(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 0fi
# 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 ;; esacdonejq '{url, status, files, uploaded_bytes}' "$RESP"Expected output, with the placeholders filled in:
deploy: d_9AQ3sK1mVx0Lq8rT2uYcZwuploaded assets/app.cssuploaded 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.
Related
Section titled “Related”- Host your users’ projects: key scopes, site names, and the CLI version of these steps.
- API keys: creating, listing, and revoking keys.
- Pricing and limits: per-account limits.
- CLI reference:
leaf deploy,leaf deploys, andleaf rollback.