Skip to main content
Kapso Functions run on Cloudflare Workers. Use them for webhooks, custom business logic, workflow steps, and agent tools.

Create and deploy

  1. Open Functions in your project
  2. Create or edit a function
  3. Deploy it
  4. Attach it to a workflow node, an agent tool, or call its endpoint directly
The Kapso CLI does not manage functions yet. Use the dashboard or API for function create/update/deploy.

Invoke endpoints

Deployed Cloudflare functions expose a Kapso-hosted invoke URL:
  • public_endpoint: false (default) keeps the invoke URL private. Send X-API-Key with the request.
  • public_endpoint: true allows invoke requests without an API key. This is only supported for Cloudflare functions.
  • Private and unknown functions both return 404 from the invoke route.
  • Newly created functions use invoke_response_mode: passthrough. Successful invoke responses preserve the function body, success status code, and Content-Type.
  • Older wrapped functions can be updated to passthrough if you need to remove the legacy { data: ... } wrapper.

Runtime contract

Kapso Cloudflare Worker functions must define:
Kapso wraps your code and calls handler(request, env). Do not use export default.

Bindings and env

  • fetch() - Make HTTP requests
  • Request/Response - Handle HTTP
  • URL/URLSearchParams - Parse URLs
  • crypto.randomUUID() - Generate IDs
  • TextEncoder/TextDecoder - Text encoding
  • env.KV - Persistent key-value storage
  • env.DB - Project database bound as Cloudflare D1
  • env.YOUR_SECRET - Access encrypted secrets set in the function page
  • Standard JavaScript APIs

Secrets

Secrets are available as string keys on env:
  • Secrets must be set in the Kapso web app (function page → Secrets tab)
  • Secret names should use UPPERCASE_WITH_UNDERSCORES
  • Values are encrypted and never exposed after creation
  • Functions must be deployed before adding secrets

KV storage

Each project has its own KV namespace for persistent data storage:

Functions in flows

Kapso sends workflow data in the JSON request body. Parse it with await request.json().

Function node

Payload keys:
  • execution_context
  • flow_info
  • flow_events
  • whatsapp_context when the run comes from WhatsApp

Decide node

next_edge is only used by decide nodes.

Agent function tools

Agent tool arguments are inside body.input, not at the root:
Payload keys:
  • input - tool arguments chosen by the agent
  • execution_context
  • flow_info
  • flow_events
  • whatsapp_context when the run comes from WhatsApp

Common patterns

WhatsApp CRM integration with session tracking