Cloud

Functions

Serverless TypeScript functions with access to the database, AI, secrets, and external HTTP. You call it from the app with a single line.

Creating a function

In Cloud → Functions, enter a name and choose a template. The editor will open, and you save the code with the Save button.

ctx API

ts
async function handler(ctx) {
  // ctx.input, ctx.user, ctx.log()
  const rows = await ctx.db.list("posts");
  const text = await ctx.ai.text("Write a greeting");
  const key = await ctx.secrets.get("STRIPE_KEY");
  const res = await ctx.fetch("https://api.example.com/x");
  return { ok: true, text };
}

Calling from the app

js
const result = await vibe.fn("send-email").invoke({
  to: "user@example.com",
  subject: "Welcome!"
});
The function is saved automatically before running.

Long-running work

Functions are for short request/response work. Do not keep a function alive with timers, sleep loops, or polling for minutes.

For time-based state, store the start time and parameters, then calculate the current value when the app reads it.

ts
const elapsed = Date.now() - Date.parse(started_at);
const capped = Math.min(elapsed, duration_seconds * 1000);
const ticks = Math.floor(capped / (tick_seconds * 1000));
const balance = initial_balance + ticks * amount_per_tick;

Limity

  • Max execution time: 15 s
  • Outbound fetch timeout: 10 s
  • Max body 10 MB