---
title: "Create function"
method: POST
path: "/functions"
tags: ["Functions"]
---

# Create function

`POST /functions`

Create a new serverless function in draft status. The function will be saved but not deployed to the runtime platform.

After creating a function:
1. Review and test the code locally
2. Deploy using POST /functions/{id}/deploy
3. Invoke using POST /functions/{id}/invoke

Choose function_type based on your deployment requirements:
- `cloudflare_worker`: Fast global edge deployment with standard JavaScript
- `supabase_function`: Deno runtime with built-in Supabase client

The function slug will be auto-generated from the name if not provided (lowercase with hyphens).

## Request body

- FunctionCreateRequest — Request to create a new serverless function. The function will be saved in draft status. Use POST /functions/{id}/deploy to deploy it to the runtime platform.
  - `function` object, required
    - `name` string, required — Function display name (user-friendly identifier)
    - `slug` string — URL-safe function identifier (optional - auto-generated from name if not provided). Must be lowercase alphanumeric with hyphens only.
    - `description` string — Optional function description
    - `code` string, required — JavaScript function code (max 1MB). Must be valid JavaScript for the target runtime. For Cloudflare Workers, use standard JavaScript. For Supabase Functions, use Deno-compatible code.
    - `function_type` 'cloudflare_worker' | 'supabase_function', required — Target serverless platform. Choose based on your deployment requirements: - `cloudflare_worker`: Fast global edge deployment, standard JavaScript - `supabase_function`: Deno runtime with built-in Supabase client
    - `public_endpoint` boolean — Allow invoke requests without an API key. Only supported for `cloudflare_worker` functions.
    - `runtime_config` object — Platform-specific runtime configuration (environment variables, resource limits, etc.)

## Response `201`

Function created successfully

- FunctionResponse — Single function response
  - `data` Function, required — Serverless function configuration. Functions are custom JavaScript code that runs on-demand in response to API invocations. Deploy functions to either Cloudflare Workers (global edge network) or Supabase Edge Functions (Deno runtime).
    - `id` string, uuid, required — Unique function identifier
    - `name` string, required — Function display name (user-friendly identifier)
    - `slug` string, required — URL-safe function identifier (lowercase alphanumeric with hyphens). Used in endpoint URLs. Must match pattern: /^[a-z0-9-]+$/
    - `lock_version` integer — Optimistic locking version. Increments on each update. Include this value on update to detect concurrent modifications — stale values return `409 Conflict`.
    - `description` string, nullable — Optional function description explaining purpose and usage
    - `code` string — JavaScript function code. Maximum size: 1 megabyte. This is the actual code that will execute when the function is invoked. Must be valid JavaScript that can run in the target environment (Cloudflare Workers or Supabase Edge Functions).
    - `version` integer, nullable — Function version number. Increments with each deployment. Use this to track which version is currently deployed in production.
    - `status` 'draft' | 'deployed' | 'error', required — Deployment status: - `draft`: Function code saved but not yet deployed to runtime - `deployed`: Successfully deployed and available for invocation - `error`: Deployment failed (check error logs for details)
    - `last_deployed_at` string, date-time, nullable — Timestamp of most recent successful deployment, null if never deployed
    - `function_type` 'cloudflare_worker' | 'supabase_function', required — Serverless runtime platform: - `cloudflare_worker`: Deploys to Cloudflare Workers (global edge network) - `supabase_function`: Deploys to Supabase Edge Functions (Deno runtime)
    - `invoke_response_mode` 'wrapped' | 'passthrough' — Controls how successful invoke responses are returned: - `wrapped`: Legacy behavior. Successful JSON responses are nested under `data`. - `passthrough`: Kapso forwards the function response body, status code, and `Content-Type` directly. Existing functions may still be `wrapped`. Newly created functions default to `passthrough`.
    - `public_endpoint` boolean — Whether the invoke endpoint can be called without an API key. Only supported for `cloudflare_worker` functions. When `true`, Kapso serves the function through the Platform API invoke route and anonymous requests are allowed.
    - `runtime_config` object, nullable — Platform-specific runtime configuration. Structure varies by function_type. Use this to configure environment variables, resource limits, or platform-specific features.
    - `endpoint_url` string, uri, nullable — Invocation URL for this function. Computed based on `function_type`. - `cloudflare_worker`: `https://api.kapso.ai/platform/v1/functions/{function_id}/invoke` - `supabase_function`: Direct Supabase Edge Function URL For private Cloudflare functions, include `X-API-Key`. For public Cloudflare functions (`public_endpoint=true`), the API key is optional.
    - `project_id` string, uuid — Project this function belongs to
    - `created_by_id` string, uuid, nullable — ID of user who created this function
    - `created_at` string, date-time, required — Function creation timestamp
    - `updated_at` string, date-time, required — Last modification timestamp

## Other responses

- `401` — Missing or invalid API key
- `422` — Request validation failed

---

[API](https://skmtc.net/kapso/apis/kapso-platform-api.md) · [All operations](https://skmtc.net/kapso/apis/kapso-platform-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/kapso/kapso-platform-api/versions/18ff5548a33f/schema)
