Functions API

The Kapso Functions API allows you to programmatically create, manage, deploy, and invoke serverless functions. Choose between Cloudflare Workers for high-performance edge computing or Supabase Functions for database-integrated serverless functions.

Overview

Functions in Kapso are serverless JavaScript functions that can be invoked via HTTP. They are perfect for:
  • Processing webhooks
  • Data transformations
  • Custom business logic
  • Integration with external services
  • Background processing
  • Database operations (with Supabase Functions)
  • User authentication workflows (with Supabase Functions)

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 Types

Functions can be deployed to different platforms:
  • cloudflare_worker (default): Deploys to Cloudflare Workers with global edge distribution
  • supabase_function: Deploys to Supabase Functions with direct database access

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

Cloudflare Workers Format

export default function handler(request) {
  // Your function logic here
  return new Response(JSON.stringify({ 
    message: "Hello from Cloudflare Worker!" 
  }), {
    headers: { "Content-Type": "application/json" }
  });
}

Supabase Functions Format

Deno.serve(async (req) => {
  // Initialize Supabase client for database access
  const supabaseClient = createClient(
    Deno.env.get('SUPABASE_URL'),
    Deno.env.get('SUPABASE_ANON_KEY')
  );

  return new Response(JSON.stringify({ 
    message: "Hello from Supabase 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

# Create Cloudflare Worker function (default)
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\"); }"
    }
  }'

# Create Supabase 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": "Database Handler",
      "description": "Handles database operations",
      "function_type": "supabase_function",
      "code": "Deno.serve(async (req) => { return new Response(\"OK\"); });"
    }
  }'

Deploy a Function

Deployment works the same for both function types - the platform is determined by the function’s function_type:
curl -X POST https://app.kapso.ai/api/v1/functions/{function_id}/deploy \
  -H "X-API-Key: YOUR_API_KEY"

Invoke a Function

Function invocation works the same regardless of platform - requests are automatically routed to the appropriate function type:
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 (e.g., “Function is not deployed” or “Supabase project required for Supabase functions”)
  • 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.