Skip to main content
Docs/Functions
DocsFunctions
Pro

Functions

Write custom TypeScript or Python backend handlers and invoke them from your generated app. Multi-tenant Cloud Run hosting, no infrastructure to manage.

Functions require a Pro or Business plan. Free workspaces can read and view existing functions but cannot create or update them.

How Functions Work

A Function is a single source file (TypeScript or Python) attached to an app. Source code lives in Google Cloud Storage; a Firestore manifest tracks which functions an app has and their metadata. At runtime, GenMB's function host loads the source, validates it, and exposes a stable HTTPS endpoint your app can call.

There is no per-app server to provision. All apps share the same function host (a Cloud Run service) and the host loads code on demand, so a brand-new Function is reachable seconds after upload.

When to reach for a Function

Use a Function when a built-in Service does not cover your need: a custom webhook, a third-party integration that needs a secret, a long-running computation, or any logic that should not live in client code.

Creating a Function

1

Open the Functions panel

From your app editor, open the Functions panel in the sidebar. You will see a list of any functions already attached to the app.
2

Choose a name and runtime

Names must be alphanumeric (underscores and hyphens allowed), up to 64 characters. Pick TypeScript (Node.js) or Python.
3

Write or paste your source

The editor opens with a starter template for the runtime you picked. Source files are capped at 100 KB. Save when ready.
4

Invoke from your app

Call your function from the generated app using a relative URL. The function is available immediately; no redeploy required.
You can also create or update functions out-of-band via PUT /api/apps/{appId}/functions/{name} with a body of {name, runtime, source}. Useful for CI, scripts, or syncing from a local repo.

Runtimes

Both runtimes receive a request-like object and return a response. The exact shape mirrors what each ecosystem expects, so familiar Node.js or Python patterns work without translation.

TypeScript

Async default export. Receives a parsed JSON body and request headers; returns any JSON-serializable value.

export default async function ({ body, headers, query }) {
  return { ok: true, received: body }
}

Python

A top-level handler(event) function. Receives a dict with body, headers, and query; returns a dict.

def handler(event):
    return {"ok": True, "received": event["body"]}

Invoking a Function

From inside your generated app, call your function with a relative path. The platform handles routing to the function host and authenticates the call on your behalf.

const res = await fetch('/api/fn/my-handler', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ amount: 12.5 }),
})
const data = await res.json()

You can also invoke directly from the editor (a small playground in the Functions panel) to test with sample input before wiring it into your UI.

Limits & Quotas

PlanMax functions / appInvocations
Free3100 / day
Pro2050,000 / month
Business100Unlimited
  • Per-function source size: 100 KB.
  • Per-invocation timeout: 30 seconds.
  • Function name: alphanumeric (with _ or -), up to 64 characters.
  • Collaborators on your app inherit the owner's plan, so they are not blocked by their own Free quota.

Security

Functions execute in the multi-tenant function host with per-app isolation. Python functions are statically analyzed before execution; imports of dangerous modules are rejected at upload time.

Python import blocklist

For Python runtimes, os, subprocess, socket, and ctypes are not allowed. Use the SDK helpers injected into the runtime for network access and database calls instead of reaching for raw modules.

Secrets your function needs (API keys, third-party tokens) belong in Environment Variables. Never paste secrets directly into source code.

Codegen Integration

When your prompt implies server-side logic, the code generator can emit Functions as part of the same pass. For example, asking GenMB for "an app that receives a Stripe webhook and updates a row" produces both the UI and a functions/stripe-webhook.ts file. After generation, the finalize step uploads the file and writes the manifest, so the function is live as soon as your app is ready to preview.

You can iterate on a generated Function the same way you iterate on any other file: ask in chat ("make stripe-webhook also send an email") and the refinement pipeline updates the Function source and re-uploads it.

FAQs

What are GenMB Functions?
Functions are small backend handlers written in TypeScript or Python that run on GenMB's multi-tenant function host. Each function is a single file invoked via a stable URL, so your generated app can call custom server-side logic without spinning up a separate backend.
How are Functions different from Services?
Services (window.genmb.storage, window.genmb.auth, etc.) are built-in capabilities GenMB provides out of the box. Functions are code you write to handle custom logic (a webhook receiver, a paid integration, a domain-specific calculation). Use Services for common needs; write a Function when you need bespoke server-side behavior.
Which runtimes are supported?
TypeScript (Node.js) and Python. Each function declares its runtime on upload; both can coexist in the same app.
Are there limits on what a Python function can do?
Yes. For safety, Python functions are AST-validated before execution. Imports of os, subprocess, socket, and ctypes are rejected. Networking and database access are available through the GenMB SDK helpers injected into the runtime.
How are Functions billed?
Functions count against your plan's function quota (number of functions per app) and invocation quota (per-day on Free, per-month on Pro). They do not deduct credits per invocation today; quota is the enforcement layer.
Can codegen create Functions for me?
Yes. When the AI determines your prompt needs custom backend logic (a Stripe webhook, a scheduled cleanup, a PDF generator), it emits a functions/{name}.{ts,py} file in the generated tree. The finalize step uploads it and registers the manifest automatically.

Ready to build?

Create your first app for free, no credit card required.