Functions API

The Kapso Functions API allows you to programmatically create, manage, deploy, and invoke serverless functions that run on Cloudflare Workers.

Overview

Functions in Kapso are serverless JavaScript/TypeScript functions that can be invoked via HTTP. They are perfect for:
  • Processing webhooks
  • Data transformations
  • Custom business logic
  • Integration with external services
  • Background processing

Authentication

All Functions API endpoints require authentication via API key. Include your API key in the X-API-Key header:
curl https://app.kapso.ai/api/v1/functions \
  -H "X-API-Key: YOUR_API_KEY"

Base URL

All API endpoints are relative to:
https://app.kapso.ai/api/v1

Key Concepts

Function Status

Functions can be in one of three states:
  • draft: Function is created but not deployed
  • deployed: Function is deployed and can be invoked
  • error: Function deployment failed

Function Code

Functions are written in JavaScript/TypeScript and follow the Cloudflare Workers format:
export default function handler(request) {
  // Your function logic here
  return new Response(JSON.stringify({ 
    message: "Hello from Kapso Function!" 
  }), {
    headers: { "Content-Type": "application/json" }
  });
}

Deployment

Functions must be deployed before they can be invoked. Deployment is asynchronous - the API returns immediately and deployment happens in the background.

Common Operations

Create a Function

curl -X POST https://app.kapso.ai/api/v1/functions \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "function": {
      "name": "Process Webhook",
      "description": "Processes incoming webhooks",
      "code": "export default function handler(request) { return new Response(\"OK\"); }"
    }
  }'

Deploy a Function

curl -X POST https://app.kapso.ai/api/v1/functions/{function_id}/deploy \
  -H "X-API-Key: YOUR_API_KEY"

Invoke a Function

curl -X POST https://app.kapso.ai/api/v1/functions/{function_id}/invoke \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "data": "your request payload"
  }'

Rate Limits

Function invocations are tracked for billing purposes. Rate limits depend on your subscription plan.

Error Handling

The API uses standard HTTP status codes:
  • 200 - Success
  • 201 - Created
  • 204 - No Content (for DELETE)
  • 400 - Bad Request
  • 401 - Unauthorized
  • 404 - Not Found
  • 422 - Unprocessable Entity
  • 500 - Internal Server Error
Error responses include a JSON body with an error field:
{
  "error": "Function is not deployed"
}

Next Steps

Explore the API endpoints in detail using the navigation on the left.