Create Edge Function

POST /v1/account/edge-functions

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

name string Req
Display name, at most 120 characters, no line breaks or NUL. Must be unique in the account (case-insensitive).
phase string
on_http_request (default) or on_http_response.
entry string
The handler export to run: a JavaScript identifier (letters, digits, _ or $, not starting with a digit), at most 64 characters. Default default.
timeout_ms integer
Per-invocation time budget, 1–1000 ms. Default 50.
memory_mb integer
Per-invocation memory ceiling, 8–256 MiB. Default 64.
source string
Optional JavaScript source, at most 524,288 bytes (512 KiB). An empty string is the same as leaving it out.

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

400 Bad Request
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.
401 Unauthorized
Missing or invalid auth.
403 Forbidden
The caller lacks 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).
409 Conflict
An edge function named "…" already exists in this account.
413 Payload Too Large
source too large (max 524288 bytes).
415 Unsupported Media Type
The request has no Content-Type: application/json header.
422 Unprocessable Entity
source failed the AI security check — the scan found the code unsafe, or the scan could not run. Nothing was created.
500 Internal Server Error
failed to check edge function quota, failed to check edge function name or failed to create edge function.
503 Service Unavailable
edge function create is busy — please retry — another create for the same account holds the lock.
Request — draft
curl -X POST "https://api.ngris.com/v1/account/edge-functions" \ -H "X-API-KEY: <your_api_key>" \ -H "Content-Type: application/json" \ -d '{ "name": "add-security-headers", "phase": "on_http_response", "timeout_ms": 50, "memory_mb": 64 }'
Request — with source (builds at once)
curl -X POST "https://api.ngris.com/v1/account/edge-functions" \ -H "X-API-KEY: <your_api_key>" \ -H "Content-Type: application/json" \ -d '{ "name": "add-security-headers", "phase": "on_http_response", "source": "<JavaScript source, as one JSON string>" }'
Response — 201 Created (draft)
{ "edge_function": { "uuid": "019b1f24-1a62-7d27-8411-538ed86e2a62", "account_uuid": "019b24b5-135e-7590-888e-e7cfa7e28ff3", "name": "add-security-headers", "entry": "default", "phase": "on_http_response", "timeout_ms": 50, "memory_mb": 64, "status": "draft", "created_at": "2026-10-12T09:14:03Z", "updated_at": "2026-10-12T09:14:03Z", "disabled_by_plan": false } }
On this page
Create Edge Function