Skip to main content
POST
/
functions
Create function
curl --request POST \
  --url https://api.kapso.ai/platform/v1/functions \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <api-key>' \
  --data '{
  "function": {
    "name": "Calculate Shipping Cost",
    "slug": "calculate-shipping-cost",
    "description": "Calculates shipping cost based on weight, distance, and service level",
    "code": "export default async function(request) {\n  const { weight, distance, service } = await request.json();\n  const baseCost = weight * 0.5;\n  const distanceCost = distance * 0.1;\n  const serviceFee = service === '\''express'\'' ? 10 : 0;\n  return new Response(JSON.stringify({\n    cost: baseCost + distanceCost + serviceFee\n  }));\n}\n",
    "function_type": "cloudflare_worker",
    "runtime_config": {
      "timeout": 30,
      "memory": 128
    }
  }
}'
{
  "data": {
    "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
    "name": "<string>",
    "slug": "calculate-shipping-cost",
    "description": "<string>",
    "code": "<string>",
    "version": 123,
    "status": "draft",
    "last_deployed_at": "2023-11-07T05:31:56Z",
    "function_type": "cloudflare_worker",
    "runtime_config": {},
    "endpoint_url": "https://api.kapso.ai/platform/v1/functions/{function_id}/invoke",
    "cf_worker_url": "https://your-function.workers.dev",
    "project_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
    "created_by_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
    "created_at": "2023-11-07T05:31:56Z",
    "updated_at": "2023-11-07T05:31:56Z"
  }
}

Authorizations

X-API-Key
string
header
required

Body

application/json

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

Response

Function created successfully

Single function response

data
object
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).