Deploy and rollback
On this page
Deploy (POST /deploy)Rollback (POST /rollback)Delete function (DELETE /functions/:id)Multi-file deploysRollback from the dashboardDeploy historyVersioningDeploy (POST /deploy)
Deploy a function to your active workspace. The script must be an ES module with a default export (e.g. export default { fetch(request) { ... } }). Functions are scoped to the workspace selected at deploy time.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Function name: lowercase alphanumeric and hyphens, 1-63 chars, must start with alphanumeric |
| code | string | Yes | Full script source (max 5 MB) |
| intent | object | No | Optional deploy intent |
| intent.bindings | string[] | No | Bindings to attach, e.g. ["key-value:user-store", "database:orders"] |
Example
curl -X POST https://api.fold.run/deploy \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "my-api",
"code": "export default { async fetch(request, env) { return new Response(\"Hello\"); } }"
}'Response
- 201 (new) or 200 (update):
function_id,url,version,status,activations_url,deployed_at. - 4xx/5xx: See Troubleshooting for error codes (e.g.
TENANT_NOT_FOUND,BINDING_NOT_FOUND,CODE_INVALID).
The url is your live endpoint: https://{tenant}.fold.run/{name} for the default workspace, or https://{workspace}.{tenant}.fold.run/{name} for non-default workspaces. See Workspaces for details.
Deploy with bindings
Attach platform resources (KV, DB, Storage, Queues) by including bindings in the deploy intent:
curl -X POST https://api.fold.run/deploy \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "my-api",
"code": "export default { async fetch(request, env) { const val = await env[\"cache\"].get(\"key\"); return new Response(val || \"miss\"); } }",
"intent": {
"bindings": ["key-value:cache"]
}
}'Binding format is TYPE:name where name is the logical binding name for the organization (must exist in /bindings and be allowed for the organization). See Bindings for details.
Deploy with the CLI
# Deploy from a file
fold deploy ./index.ts --name my-api --tenant my-tenant
# Deploy with bindings
fold deploy ./index.ts --name my-api --binding "key-value:cache"
# Deploy from a directory (TypeScript bundled automatically)
fold deploy ./src/ --name my-apiThe CLI automatically bundles TypeScript (ESM, tree-shaking, minified). Use --no-bundle to skip bundling.
What happens during deploy
- Validate organization exists and is within plan limits
- Check that all requested bindings are allowed
- Bundle the code and store in object storage (versioned)
- Load organization secrets and inject as environment bindings
- Record the deployment in the database
- Invalidate the routing cache
- Generate an AI summary of the deployment (async, never blocks)
Rollback (POST /rollback)
Revert a function to a previous version. You need the function ID (from deploy or GET /functions) and the target version number.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
| function_id | string | Yes | Function ID |
| version | number | Yes | Version number to restore |
Example
curl -X POST https://api.fold.run/rollback \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"function_id": "fn_abc123",
"version": 2
}'Response
- 200:
function_id,rolled_back_to,new_version,status,deployed_at. - 404
VERSION_NOT_FOUND: That version does not exist for this function.
Rollback restores the exact code from the specified version and re-injects current secrets as bindings.
Via the CLI
fold rollback fn_abc123 2Delete function (DELETE /functions/:id)
Permanently delete a deployed function and its activation records. Requires the function ID.
curl -X DELETE "https://api.fold.run/functions/fn_abc123" \
-H "Authorization: Bearer YOUR_TOKEN"Response
- 200:
{ "deleted": true }. - 404: Function not found.
After delete, the subdomain will return 404 for that organization until another function is deployed.
Multi-file deploys
Deploy multiple files as an ES module bundle:
curl -X POST https://api.fold.run/deploy \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "my-api",
"files": {
"index.ts": "import { handler } from \"./handler.ts\"; export default { fetch: handler };",
"handler.ts": "export function handler(req) { return new Response(\"Hello\"); }"
},
"entry": "index.ts"
}'| Field | Type | Required | Description |
|---|---|---|---|
| files | object | No | Map of file paths to source code (alternative to code) |
| entry | string | No | Entry point file (defaults to index.ts or the first file) |
Total size across all files must be under 10 MB. Provide either code (single file) or files (multi-file) — not both.
Rollback from the dashboard
The deploy history page at app.fold.run/console/deploys shows a timeline of all deployments. Each deploy with version > 1 has a Rollback button that reverts to the previous version with one click.
Deploy history
View all deployments across your functions:
curl "https://api.fold.run/deploys?limit=25" \
-H "Authorization: Bearer YOUR_TOKEN"Returns function name, version, status, deployer, timestamp, and an AI-generated summary for each deploy.
Versioning
Every deploy increments the function's version number. You can view all versions and rollback to any previous version. The platform stores the full source code for each version in object storage.
List functions to see current versions:
curl "https://api.fold.run/functions" \
-H "Authorization: Bearer YOUR_TOKEN"