Skip to content

Functions

A function is a small wasm program attached to a site and served on the site’s domain — by default at /_fn/<slug>. Functions run untrusted on an isolated functions node, separate from your site hosts, with declared bindings as their only capabilities. Use one to add an API route, a form handler, or an edge personalization layer next to a WordPress or static site without running a server.

Reads need functions:read; every mutation needs functions:write.

Field Type Description
id string Stable identifier, e.g. fn_01J9....
site_id string The home site. Functions transfer with it.
slug string User-facing name; the default route is /_fn/<slug>.
display_name string Human label.
language string Guest language: javascript (default), typescript, rust, tinygo, go, c, zig, or swift.
bindings object[] Declared capabilities — each { kind, name, config }.
env / secret_refs object / string[] Plain env vars and references to platform-held secrets.
limits object Per-instance limits (memory, wall-clock, request bytes, rps).
route_path string Route override; empty means the default /_fn/<slug>.
build_status string Paste-source build lifecycle: empty, building, deploying, live, or failed.
active_version_id string The version currently serving.
last_build_job_id / last_artifact_id string The most recent build job and the wasm artifact it produced.
created_at / updated_at string RFC 3339 timestamps.

A function can only touch what it declares:

Kind Grants
kv A named key-value store.
coord Coordination primitives (locks, counters).
fetch Outbound HTTP to the configured destination.
service Calls to another function.

cron bindings are rejected with 400 binding.unsupported — scheduled execution is a trusted-tier capability, and functions run untrusted by design.

  • GET /v1/functionsfunctions:read every function you own, cursor-paginated.
  • GET /v1/sites/{siteID}/functionsfunctions:read the per-site view.
  • GET /v1/functions/{functionID}functions:read one function.

functions:write Create a function on one of your sites. Returns 201 with the function. If you include inline source, the platform builds it and — with auto_deploy (the default) — deploys it immediately.

Parameter Type Required Description
site_id string yes The home site — you must be able to manage it.
slug string yes Lowercase letters, digits, and hyphens; sets the default route /_fn/<slug>.
display_name string yes Human label.
language string no Defaults to javascript. An unsupported value returns 400 language.unsupported.
bindings object[] no kv, coord, fetch, or servicecron is rejected.
secret_refs / env string[] / object no Secrets by reference; plain env vars inline.
limits object no Per-instance limits.
route_path string no Route override.
source string no Inline single-file source, up to 256 KiB — builds (and by default deploys) immediately.
filename string no Override the per-language default filename; a bare basename, no path separators.
auto_deploy boolean no Default true; false builds only and stages the artifact.
Create a JavaScript function from inline source
curl -X POST https://api.managed.dev/v1/functions \
-H "Authorization: Bearer mfk_live_..." \
-H "Content-Type: application/json" \
-d '{
"site_id": "site_01J7...",
"slug": "contact-form",
"display_name": "Contact form handler",
"language": "javascript",
"bindings": [{ "kind": "kv", "name": "submissions" }],
"source": "export default { async fetch(req, env) { /* … */ return new Response(\"ok\"); } }"
}'

The function then serves at https://acme-store.com/_fn/contact-form.

The three lifecycle mutations each return 202 Accepted with a job reference — { "job_id": "job_01J9...", "status": "queued" } — that you track through the jobs API. Deploys surface as deployment.wasm_deploy jobs, rollbacks as deployment.wasm_rollback.

functions:write (Re)build the function from pasted single-file source, or rebuild the stored source when the body is empty. With auto_deploy (the default) the build rolls out as soon as it succeeds.

Parameter Type Required Description
source string no New single-file source (≤ 256 KiB); absent rebuilds the stored source.
filename string no Per-language filename override.
auto_deploy boolean no Default true; false stages the artifact only.

functions:write Deploy a prebuilt .wasm artifact — one you built with auto_deploy: false, or a previous build you’re re-rolling.

Parameter Type Required Description
artifact_id string yes A built wasm artifact belonging to this function.

functions:write Flip the function back to a prior version.

Parameter Type Required Description
version_id string yes The prior function version to reactivate.
Rebuild the stored source
curl -X POST https://api.managed.dev/v1/functions/fn_01J9.../build \
-H "Authorization: Bearer mfk_live_..."

functions:write Remove the function from the functions node and delete its record. A missing function returns 404 function.not_found.

You don’t need a deploy cycle to iterate. The mf CLI ships a docker-based local runner that mirrors the platform’s capability tier:

  1. Install the builder images for your language: mf fn setup --lang js (also ts, tinygo, rust, c, zig, swift).
  2. Serve a module or source directory locally: mf fn dev ./contact-form --watch (JavaScript watch loop) — it listens on 127.0.0.1:8787 by default.
  3. Declare the same bindings you’ll deploy with: mf fn dev module.wasm --binding kv:submissions --env DEBUG=1 --kv submissions:seed=1.
  4. Run one-shot requests for tests: mf fn dev module.wasm --once --request req.json.
  5. Build without deploying: mf fn dev --build ./contact-form --lang tinygo --out fn.wasm.

When it works locally, mf functions build / mf functions deploy ship the same code to the functions node.