Create Edge Function
Add an edge function to your active account's library. Without source the function is created as a draft; upload the code later with Upload Edge Function Source. With source the code is scanned, saved, and a build is queued in the same call (the function starts as building).
The source is JavaScript, compiled to a WebAssembly bundle (Javy / QuickJS). At the edge the handler reads one JSON request on stdin (method, url, path, headers, body as base64) and writes one JSON response to stdout (status, headers, body as base64). There is no network, filesystem or timer access.
Before it is saved, every source passes an AI security check; a source that fails it — or a check that can't run — is refused (422), nothing is created. Once the build is ready, attach the function to an endpoint with an edge-function traffic-policy rule carrying its bundle_key and bundle_hash (Add Rule).
Requires the endpoints:write permission on the active account and the edge_functions plan entitlement. The number of edge functions per account is capped by the same entitlement's limit (library and application functions together).
Request body
on_http_request (default) or on_http_response._ or $, not starting with a digit), at most 64 characters. Default default.1–1000 ms. Default 50.8–256 MiB. Default 64.Fields not listed are ignored.
Response (201 Created)
{"edge_function": { … }} — the new function (fields: the edge function object), status draft, or building when source was sent (failed if its build could not be started — the source could not be staged or the build queued; the function still exists, so save the source again with Upload Edge Function Source to retry). Poll Get Edge Function until it is ready or failed.
Deprecated: until the sunset this response also carries the legacy integer id and *_id fields. Don't use them; read uuid and the *_uuid fields.
Errors
invalid JSON body, or a field that fails validation: name is required, name too long (max 120), name must not contain control characters, phase must be one of: on_http_request, on_http_response, entry too long (max 64), entry must be a JS identifier …, timeout_ms must be 1..1000, memory_mb must be 8..256.endpoints:write; the plan doesn't include edge_functions (code entitlement_required); the account is at its edge-function limit (Edge function limit reached (…) — delete one or upgrade your plan); or the account is suspended (code account_suspended).An edge function named "…" already exists in this account.source too large (max 524288 bytes).Content-Type: application/json header.source failed the AI security check — the scan found the code unsafe, or the scan could not run. Nothing was created.failed to check edge function quota, failed to check edge function name or failed to create edge function.edge function create is busy — please retry — another create for the same account holds the lock.