v1
latestOpenAPI 3.1.02026-07-22115189303.8 KBFunctions
Create function
Create a new serverless function in draft status. The function will be saved but not deployed to the runtime platform.
After creating a function:
- Review and test the code locally
- Deploy using POST /functions/{id}/deploy
- 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).
post/functions
Request body
Example request
{
"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
}
}
}Response
Function created successfully
Example response
{
"data": {
"slug": "calculate-shipping-cost",
"endpoint_url": "https://api.kapso.ai/platform/v1/functions/{function_id}/invoke"
}
}