Your First Function in 2 Minutes
A Vybase Function is a TypeScript or JavaScript file that answers web requests with the standard Request/Response API (the same as Supabase Edge Functions and Cloudflare Workers). Create one in the console (Functions → New function, with templates), ask Vybase AI, or use the CLI:
npx vybase functions new hello # writes vybase/functions/hello/index.ts
npx vybase functions serve # http://localhost:8788/hello, secrets from vybase/functions/.env
npx vybase functions deploy --project prj_… # bundles npm packages on your computer and deploys
export default async function (req: Request, ctx) {
const { name } = await req.json();
return Response.json({ message: `Hello ${name}!`, user: ctx.user?.id });
}
ctx.user is the signed-in caller (with custom claims), ctx.waitUntil(promise) keeps working after you answer, ctx.executionId matches the logs. Code written for Supabase (Deno.serve(handler), Deno.env.get()) runs as it is.
Call It from Your App
const { data, error } = await zyv.functions.invoke("hello", { body: { name: "Asha" } });
// Long work: answers 202 at once, runs in the background with 3 tries
await zyv.functions.invoke("monthly-report", { body: { month: "2026-11" }, background: true });
- Flutter:
await zyv.functions.invoke('hello', body: {'name': 'Asha'})· Python:zyv.functions.invoke("hello", body={...}) - Any client or webhook:
https://auth.zyvraone.site/functions/v1/<project id>/<name> - Same origin on your Vybase site (no CORS):
vybase.json→{ "rewrites": [{ "source": "/api/*", "function": "api" }] } - Who can call:
signed_in(default, a user's access token),public(payment webhooks) orsecret(only your server). CORS is answered for you.
Secrets (Keep API Keys Out of Your App)
Never put OpenAI, Razorpay or other keys in browser or mobile code. Save them as secrets and read process.env.NAME. Every function also gets VYBASE_URL, VYBASE_PROJECT_ID, VYBASE_PUBLISHABLE_KEY and VYBASE_SECRET_KEY to call the Database and Email APIs.
npx vybase functions secrets set OPENAI_API_KEY=sk-…
Cron Jobs in Your Time Zone
export async function scheduled(event, ctx) {
// event = { type: "schedule", cron: "0 9 * * *", timezone: "Asia/Kolkata", scheduled_time }
console.log("Daily report", event.scheduled_time);
}
Add the schedule in the console (Schedules & triggers), with Vybase AI, or in vybase.config.json. Free plan: 5 schedules, every 5 minutes at most. Pro: 50, every minute.
Triggers: Database, Auth, Storage & Forms
Run code when something happens. Database events have the same shape as Supabase Database Webhooks, but failed runs are tried again (now, after 30 s, after 5 min).
// db.insert on "orders" → e = { type: "INSERT", table: "orders", record, old_record: null }
export async function event(e, ctx) {
if (e.type === "INSERT" && e.record.total > 5000) console.log("Big order", e.record.id);
}
auth.user.created·auth.user.deleted·auth.user.signed_indb.insert·db.update·db.delete(per collection)storage.object.created·storage.object.deleted(per bucket) ·form.submitted
Auth Hooks
- Before sign-up: return
{ allow: false, message: "Use your college email." }to refuse a sign-up. - Custom access token: return
{ claims: { app_role: "admin" } }to add claims to every token (and toctx.user).
Functions in vybase.config.json
{
"version": 1,
"functions": {
"daily-report": {
"access": "secret",
"schedules": [{ "cron": "0 9 * * *", "timezone": "Asia/Kolkata" }],
"secrets": ["OPENAI_API_KEY"]
},
"on-order": { "triggers": [{ "event": "db.insert", "filter": "orders" }] }
},
"auth": { "hooks": { "custom_access_token": "add-role" } }
}
Limits, Logs & Safety
- Free: 25 functions per project, 50,000 calls a month, 30 s and 256 MB per call, 5 calls at once, logs kept 1 day.
- Pro (₹299/month): 250 functions, 2,000,000 calls, 150 s and 512 MB, 25 at once, logs kept 7 days.
- Sandbox: every call runs in its own process as its own Linux user with no capabilities, reads only its own code and writes only its own
/tmp, and can't reach private networks. - Versions: the last 20 deployments are kept; roll back in one click. The security check warns about API keys written in code and secrets that aren't set.
- Errors:
sign_in_required,function_forbidden,function_not_found,function_timeout,function_crashed,function_error,function_busy,function_calls_limit,function_build_failed.