All docs

Functions

Functions

Run short-lived code triggered by HTTP or a schedule.

Creating functions

Functions live in the `functions/` directory. Each file exports a default handler:

ts
// functions/hello.ts
export default async function handler(req: Request) {
  return new Response(JSON.stringify({ message: "Hello, world!" }), {
    headers: { "Content-Type": "application/json" },
  });
}

Triggers

HTTP

Functions are automatically available at `/api/<filename>`. The `hello` function above is accessible at `/api/hello`.

Cron

Schedule functions to run on a cron expression:

ts
export const config = {
  cron: "0 */6 * * *", // Every 6 hours
};

Environment

Functions have access to the same environment variables and secrets as the rest of your project. They run in isolated runtimes with their own resource limits.