ScalixScalix Docs
Sign up

Functions

Serverless function deployment, invocation, and management

Overview

Scalix Functions let you deploy and invoke serverless functions with multiple runtime support. Functions scale to zero when idle. Warm invocations return in ~15ms; a cold start (full Firecracker microVM boot) takes ~1.6s.

Quick start

Create a function:

typescript
// handler.ts — the payload object is the FIRST ARGUMENT (handler mode)
export default async function handler(payload) {
  return { result: payload.x + payload.y };
}

Deploy:

bash
scalix-cloud fn deploy add --source . --runtime node --handler handler.handler

fn deploy requires either --source <path> or --image <image>.

Invoke:

bash
scalix-cloud fn invoke add --data '{"x": 1, "y": 2}'

Handler contract (handler mode)

By default a function runs in handler mode, and the contract is deliberately minimal:

  • The first argument is the invoke payload: the object you pass to fn invoke (--data). Triggered invocations (cron, events) pass their trigger payload the same way. There is no Request wrapper and no await req.json().
  • Return a value (or a promise). It is serialized as JSON into the invoke response as output, together with collected logs and an exit_code.
  • Errors bubble as invoke errors: a thrown exception fails the invocation with the exception message; a 2xx invoke means the handler returned.
typescript
// handler.ts (Node)
export default async function handler(payload) {
  const total = (payload.items ?? []).reduce((sum, i) => sum + i.price, 0);
  return { total, count: payload.items?.length ?? 0 };
}
python
# handler.py (Python)
def handler(payload):
    return {"echo": payload.get("message", "")}

The entry point is module.function (default index.handler): set --handler at deploy time, e.g. --handler src/main.process. HTTP-mode functions (deployed with invocation_mode: http) run their own HTTP listener instead and are invoked through their function URL; see the API reference for the deploy fields.

REST API

Deploy a function

bash
curl -X POST https://api.scalix.world/v1/functions \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -d '{
    "name": "process-order",
    "runtime": "node",
    "image_ref": "api.scalix.world/<project-id>/process-order:latest",
    "handler": "index.handler",
    "timeout_ms": 30000,
    "memory_mb": 256,
    "env": { "STRIPE_KEY": "sk_..." }
  }'

Invoke a function

bash
curl -X POST https://api.scalix.world/v1/functions/{id}/invoke \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -d '{"order_id": "ord_123"}'

List functions

bash
scalix-cloud fn list

View invocation logs

bash
curl https://api.scalix.world/v1/functions/{id}/invocations \
  -H "Authorization: Bearer $SCALIX_API_KEY"

Supported runtimes

RuntimeValue
Node.jsnode
Pythonpython

Scheduled functions

Deploy the function, then schedule it with a cron job that invokes it. Create the schedule with Cron:

bash
# Deploy the function
scalix-cloud fn deploy daily-report --runtime node --source <git-url>
 
# Schedule it: <name> <cron-expression>, targeting the function
scalix-cloud cron create daily-report "0 6 * * *" \
  --action-type function \
  --config '{"function_id":"daily-report"}'

Resource limits

SettingDefaultMax
Timeout30s300s
Memory128 MB4 GB
vCPUs0.252
Payload6 MB6 MB