Deploy a function
Creates and deploys a new function. The handler must be a single ESM module whose default export is an object with an async fetch(request, env) method (Workers-style). Primitive signs each delivery and forwards the Primitive-Signature header to the handler. Verify the raw request body with PRIMITIVE_WEBHOOK_SECRET before parsing JSON; after verification the request body parses to a webhook event whose event field is email.received for normal inbound mail, or a machine-mail type (email.bounced, email.tls_report, email.dmarc_report, email.dmarc_failure) for bounces and reports. Code is bundled before being uploaded; ship a single self-contained file rather than relying on external imports.
Code limits. code is capped at 1 MiB UTF-8. sourceMap (optional) is capped at 5 MiB UTF-8, stored with each deployment attempt, and sent to the runtime so stack traces can resolve to original source files.
Routing. On successful deploy, the function code is live in the runtime, but inbound mail will not reach it until at least one route is bound. Routes are managed from the Primitive dashboard. A deploy_status of deployed means the script is installed, not that the function is receiving mail. The internal runtime URL is not returned by the API and is not a customer-facing integration surface.
Secrets. New functions ship with the managed secrets (PRIMITIVE_WEBHOOK_SECRET, PRIMITIVE_API_KEY, PRIMITIVE_API_BASE_URL) already bound. Add user-set secrets via POST /functions/{id}/secrets; secret writes only land in the running handler on the next redeploy.
Headers
Optional client-supplied idempotency key. Retrying a request with the same key returns the original result instead of performing the action a second time; if omitted the server derives one from the canonical payload hash. Safe to retry network failures without duplicating side effects.
Request body
Response
Function created and deployed