Skip to content
excalibase
quickstart
Edge Functionsbeta

Quick Start

On Excalibase Cloud

1. Write the handler

index.ts default-exports a function from Request to Response:

export default async (req: Request): Promise<Response> => {
  const { args } = await req.json();
  return Response.json({ data: { message: "Hello, " + args.name + "!" } });
};

2. Deploy it

In Studio, open Edge Functions, create a function with the id hello and paste the file. From an AI tool, call the MCP deploy_function tool with id: "hello" and the file as index.ts. A file without a default export is refused at this step with a message naming what it found.

3. Call it

With the project's token (Connect to your project has the token exchange):

curl -s -X POST "https://api.excalibase.io/functions/v1/$PROJECT_ID/hello" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"args": {"name": "World"}}'
# {"data":{"message":"Hello, World!"}}

or with the SDK (@excalibase/sdk 0.13 or later):

const { message } = await db.functions.hello({ name: "World" });

Something wrong? console.log output and thrown errors are in the function's logs: Studio, or the MCP get_logs tool with source: "function".

Self-hosting

The /deploy and /invoke/{id} calls below are the function runtime's own API. They are self-hosted only and answer 404 on api.excalibase.io. The runtime takes already-bundled JavaScript; the platform bundles index.ts for you.

1. Deploy a function

curl -X POST http://localhost:24006/deploy \
  -H "Content-Type: application/json" \
  -H "X-Runtime-Secret: $RUNTIME_SECRET" \
  -d '{
    "id": "hello",
    "code": "export default async (req) => { const { args } = await req.json(); return Response.json({ data: { message: \"Hello, \" + args.name + \"!\" } }); };"
  }'
{ "id": "hello", "url": "/invoke/hello" }

2. Invoke it

/invoke/{id} takes the request to hand the handler and answers with its response:

curl -X POST http://localhost:24006/invoke/hello \
  -H "Content-Type: application/json" \
  -H "X-Runtime-Secret: $RUNTIME_SECRET" \
  -d '{"method": "POST", "url": "/hello", "headers": {}, "body": "{\"args\": {\"name\": \"World\"}}"}'
{ "status": 200, "headers": { "content-type": "application/json" }, "body": "{\"data\":{\"message\":\"Hello, World!\"}}" }

Managing functions

# List all functions
curl -H "X-Runtime-Secret: $RUNTIME_SECRET" http://localhost:24006/scripts

# A function's logs
curl -H "X-Runtime-Secret: $RUNTIME_SECRET" http://localhost:24006/logs/hello

# Delete a function
curl -X DELETE -H "X-Runtime-Secret: $RUNTIME_SECRET" http://localhost:24006/delete/hello

Next