Skip to main content

Functions

Serverless TypeScript/JavaScript functions powered by V8 isolates. Deploy in seconds, invoke instantly — < 5ms cold starts with no container overhead.

< 5ms Cold Start

V8 isolates spin up in microseconds — 100× faster than container-based functions. No waiting.

TypeScript Native

Write TypeScript directly — no build step. The runtime compiles on first invocation and caches.

Web Standard APIs

Full access to fetch, Request, Response, crypto, URL, TextEncoder, and the entire Web API surface.

Per-Project Isolation

Each function runs in its own V8 isolate. Memory is bounded. No shared state between projects.

Invocation Logs

Every invocation is logged — status code, duration, error messages — visible in the console.

npm via CDN

Import any npm package via CDN URL (esm.sh, jspm). No install step, no node_modules.

Functions vs Tasks vs Runs

  • Functions — Lightweight HTTP handlers. Any HTTP request → V8 isolate → Response. Best for webhooks, APIs, data transforms.
  • Tasks — Durable TypeScript handlers with queues, retries, step.run, and step.waitForEvent. Best for long-running async work.
  • Runs — Container-based batch compute. Bring any Docker image. Best for ML training, ETL, and multi-language workloads.

Quick Start

Write a function handler, deploy it with the CLI, and get a live URL immediately.

functions/hello-world/index.ts
// Every function exports a default async handler
// req: standard Web API Request object
// return: standard Web API Response object

export default async function handler(req: Request): Promise<Response> {
  const url = new URL(req.url)
  const name = url.searchParams.get('name') ?? 'World'

  return Response.json({
    message: `Hello, ${name}!`,
    timestamp: new Date().toISOString(),
  })
}
Terminal
# Deploy the function
sylphx functions deploy hello-world --file ./functions/hello-world/index.ts

# Output:
#   Name:    hello-world
#   Version: 1
#   Status:  ● active
#   URL:     https://my-project.sylphx.app/functions/hello-world

# Invoke it immediately
curl "https://my-project.sylphx.app/functions/hello-world?name=Claude"
# → { "message": "Hello, Claude!", "timestamp": "2026-04-06T..." }

Using Sylphx BaaS in Functions

Functions can access any Sylphx BaaS service using the server SDK. The SYLPHX_SECRET_KEY env var is automatically injected at runtime.

functions/create-user/index.ts
import { createConfig, createServerClient } from 'https://esm.sh/@sylphx/sdk/server'

const config = createConfig({
  secretKey: Deno.env.get('SYLPHX_SECRET_KEY')!,
})

export default async function handler(req: Request): Promise<Response> {
  if (req.method !== 'POST') {
    return new Response('Method Not Allowed', { status: 405 })
  }

  const { email, name } = await req.json()

  // Auth — create a new user
  const client = createServerClient(config)
  const user = await client.auth.createUser({ email, name })

  // KV — cache the user profile
  const { kv } = await import('https://esm.sh/@sylphx/sdk/server')
  const kvClient = kv(config)
  await kvClient.set(`user:${user.id}`, user, { ttl: 3600 })

  return Response.json({ userId: user.id }, { status: 201 })
}

Importing npm Packages

Since functions run in Deno, npm packages are imported via CDN URL rather than npm install. Use esm.sh for best compatibility.

functions/validate-schema/index.ts
// Import npm packages via esm.sh CDN
import { z } from 'https://esm.sh/[email protected]'
import { Hono } from 'https://esm.sh/hono@4'

const app = new Hono()
const schema = z.object({ email: z.string().email(), age: z.number().min(18) })

app.post('/validate', async (c) => {
  const body = await c.req.json()
  const result = schema.safeParse(body)

  if (!result.success) {
    return c.json({ errors: result.error.flatten() }, 400)
  }

  return c.json({ valid: true, data: result.data })
})

export default app.fetch

SDK — Programmatic Deploy

import { createConfig, FunctionsClient } from '@sylphx/sdk'

const config = createConfig({ secretKey: process.env.SYLPHX_SECRET_KEY! })

// Deploy (create or update — idempotent)
const fn = await FunctionsClient.deploy(config, {
  name: 'send-webhook',
  code: `
    export default async (req: Request) => {
      const { url, payload } = await req.json()
      await fetch(url, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(payload),
      })
      return Response.json({ delivered: true })
    }
  `,
  timeoutSeconds: 10,
  memoryMb: 64,
})

console.log('Deployed:', fn.url)

// Invoke server-to-server
const result = await FunctionsClient.invoke(config, 'send-webhook', {
  url: 'https://hooks.example.com/notify',
  payload: { event: 'order.created', orderId: '123' },
})

// Fetch recent logs
const logs = await FunctionsClient.logs(config, 'send-webhook', {
  limit: 20,
  errorsOnly: true,
})

Runtime Limits

PropertyTypeDescription
MemoryintegerDefault 150 MB, max 512 MB
Execution timeoutdurationDefault 30s, max 120s
Code sizesizeMax 512 KB inline; use CLI for larger bundles
Allowed APIsstringFull Web Standard API (fetch, crypto, URL, TextEncoder, etc.)
Disallowed APIsstringNo filesystem (fs), no raw sockets (net), no child_process
npm packagesstringImport via CDN URL (esm.sh). Pure-JS packages only — no native bindings.
RuntimestringDeno (V8 isolates via Supabase Edge Runtime)

API Reference

PropertyTypeDescription
POST /sdk/functionsendpointDeploy (create or update) a function. Returns deploy result with live URL.
GET /sdk/functionsendpointList all functions for this project.
GET /sdk/functions/:nameendpointGet a function by name.
DELETE /sdk/functions/:nameendpointPermanently delete a function.
POST /sdk/functions/:name/invokeendpointServer-to-server function invocation.
GET /sdk/functions/:name/logsendpointFetch recent invocation logs.