Skip to content

Flows

A flow is a workflow made of steps. Unlike an Edge Function, which answers one request, a flow can run for seconds or for weeks: it can pause for a day, wait for a payment webhook, retry a failed call and carry on after a crash.

A flow is a directed graph with one trigger and a chain of steps (nodes). The server compiles the graph into a durable program. Each step has a unique key and its result is written to a journal. If a worker dies, the run resumes from the journal: finished steps are replayed from the record instead of running again.

A run is always in one of these states: queued, running, sleeping, waiting, completed, failed or cancelled.

  1. Open Flows → New flow in the dashboard and choose a starter recipe or a blank canvas. Names use lowercase letters, digits, _ or - and start with a letter.
  2. Drag nodes from the library and wire an output port to an input port. The graph must be acyclic with one trigger, and a Condition needs both its true and false branch.
  3. Fix every validation message. Drafts autosave on the server.
  4. Test run runs the current draft without deploying it. Test runs do not count towards your monthly runs.
  5. Deploy builds an immutable version and activates it. Runs already started keep the version they began with.

From a terminal, export the graph JSON from the builder and deploy it:

Terminal window
npx potalab base flows deploy place-order --graph flow.json --access authenticated
npx potalab base flows run place-order --input '{"cartId":"c_1"}' --as anon

A flow starts from a Trigger node. One flow can hold up to 8 of them (for example a Schedule, a Webhook and a Custom event feeding the same steps), and every run records which node started it. The Test run dialog can start from any trigger node with a sample payload; test runs are not counted in your quota.

Trigger Starts when
HTTP (default) POST /flows/v1/<name> is called, see Call a flow from your app
Schedule (cron) a 5-field schedule fires, in the time zone you choose; the shortest interval depends on your plan
Database event a row is inserted, updated or deleted in a table of the public schema; for updates you can require that chosen columns changed
Called by another flow a Run flow node starts it as a child
Webhook an outside service calls the flow’s own public URL
Custom event your code emits an event with a matching name
Storage event an object is uploaded to, moved or renamed in, or deleted from a bucket
Auth event a user signs up, signs in or is deleted

Triggers that have no signed-in caller (everything except HTTP) run with an identity. Event-driven triggers (database, custom event, Storage) run as the person who caused the event by default, Auth events as the person concerned, and Schedule and Webhook ask you to choose a user or the service role explicitly. Running as the service role needs the flow to allow it, shows a warning at deploy and is audited. Such flows cannot be called over HTTP.

For an HTTP flow, choose who may call it: authenticated (default), public (the publishable key alone) or service (the secret key only). An optional caller policy adds conditions such as roles, user ids, verified email domains, tenants or MFA. A refused call answers 403 caller_not_allowed before any run exists, so it costs no quota.

Set the 5-field schedule, an IANA timezone (daylight saving aware), what to do when a run is still going (skip, queue or allow) and whether to catch up missed slots. An optional random delay of 0 to 300 seconds spreads many schedules so they do not hit your services in the same second; it can be at most half of the schedule’s shortest gap.

Every schedule must name who it runs as: a user (row security applies) or the service role. A schedule saved before this was enforced is upgraded automatically: if the flow has a user, the schedule keeps running as that user (now shown on the trigger); otherwise it is disabled and never switched to the service role. Pick an identity in the node and enable it again. A schedule without an identity never fires.

If the user a schedule runs as is later deleted or banned, the schedule is disabled once (instead of failing on every tick). Unbanning the user does not turn it back on: deploy the flow again to enable it.

Choose the table and the kind of change. Narrow it down with Only when the new row matches (up to 10 conditions) and, for updates, Only when these columns change: list up to 20 column names and an update starts the flow only when at least one of them has a different value than before. Updates that touch other columns, or write the same value again, start nothing; inserts and deletes are not affected. The first change after a quiet period is delivered within milliseconds.

Each Webhook node has its own URL, https://<project host>/hooks/v1/<flow>/<node id>, with no API key. The signature is checked on the raw body before it is parsed and every failure gives one generic 401 (no run, no quota). The default is an HMAC signature (HMAC-SHA256(secret, body) in a header you name); there are also Stripe, GitHub, Shopify, Slack and Twilio presets, JWT verification, a secret header and a secret in the URL (only for senders that cannot sign). The shared secret (the signing secret, or the Twilio Auth Token) is a generic credential, referenced by name in the node.

  • Slack: use the signing secret of your Slack app. Slack’s url_verification request is answered for you, so you can paste the webhook URL into the Slack app right away. Requests older than 5 minutes are refused.
  • Twilio: use your Auth Token. Twilio signs the URL it called, so if a proxy or CDN changes the host before the request reaches Base, set Public URL to the origin shown in the Twilio console (for example https://api.example.com).
  • JWT: no shared secret. The sender sends Authorization: Bearer <token> and Base checks the signature with the public keys at the JWKS URL you enter (https only). Enter the issuer and/or the audience, at least one and ideally both, because an identity provider signs tokens for all of its customers. Only RS256 and ES256 are accepted unless you list others; exp is required; none and HS* tokens are always refused. The verified claims are available to the flow as http.jwt.

Replay protection. A signature that only covers the body can be replayed by anyone who captured one request. Add a timestamp header (a timestamp older or newer than tolerance_seconds, default 300 s, is refused), turn on Require a signed timestamp so deploy refuses an unsigned-timestamp webhook, and Reject replays so a signature that was accepted once is refused again. A repeated delivery with the same idempotency key returns the first run with idempotent_replay: true; delivery is at least once, so keep side effects idempotent.

An event is a name and a JSON object (up to 64 KB). One emit starts every flow whose Custom event trigger matches the name and filter, and resumes runs that wait for the same event.

await base.flows.emit("order.paid", { orderId }, { eventId, asUser }) // service key
await base.flows.emit("order.requested", { sku }) // signed-in user (browser or app)

You can also emit from the Emit event step or from SQL with api.cloud_emit_event(...), in the same transaction as your data change. To let signed-in users start a flow, switch on Signed-in users may start it on the node, then they call base.flows.emit(...) with their own session (or api.cloud_emit_user_event in SQL). This path starts only triggers that opted in, never resumes waiting runs and runs as that user (asUser is ignored). Each user may emit 60 events a minute, payload up to 64 KB, and the answer never says whether the name is allowed. Anonymous callers are refused. The same event_id never starts a second run of the same trigger.

Choose a bucket, an optional path prefix and suffix, and Uploaded, Deleted, Moved or renamed, or Any change. A move or rename is a single event (the input has key as the new path and from_key as the old one); the prefix and suffix select the new path and Moved from path starting with selects the old one. The input has the event, bucket, key, size and content type but no file content (read it with a Storage node). Objects written straight into your own S3 bucket raise no events, and a flow that writes into the prefix it listens to loops until the depth limit, so write results elsewhere.

Starts a flow when a user signs up (user.signed_up), signs in (user.signed_in) or is deleted (user.deleted). It never blocks or changes the sign-up or sign-in. Sign-in fires on every login, so it is off by default and has a rate cap, a sample percentage and a provider filter. By default a sign-up flow waits until the email is verified, so a welcome email never goes to someone who typed another person’s address. A deletion needs a fixed user or the service role, because the person is gone. The input never includes user_metadata, a password hash or a token.

Group Nodes
Data query, insert and update table rows as the run identity, so row level security applies
Logic Condition, Split, Join, Loop, Filter list, Sort list, Limit list, Remove duplicates, Text, Convert JSON
Time and events Delay (for example 10m or 1d) and Wait for event
Integrations HTTP request, Run flow
AI and media model, knowledge-base, image, video, audio and storage nodes; they need a provider under Model Providers
Result Return result

An HTTP request node can reach only the hosts in the flow’s egress allowlist. An empty list, the default, blocks all outbound internet access.

Wait for event pauses the run until an event with the given name arrives and contains every key of the node’s match object. If the timeout passes first, the node returns null. A wait never lasts longer than your plan’s run timeout (7 days by default), even when you set no timeout or a longer one: the run then fails with run_timeout. Send the event from your server with the secret key:

Terminal window
curl -X POST "https://<management-url>/v1/projects/{ref}/flows/events" \
-H "Authorization: Bearer $POTALAB_BASE_SERVICE_KEY" \
-H "Content-Type: application/json" \
-d '{ "event": "order.paid", "match": { "order_id": "o_1" }, "payload": { "amount": 120000 } }'

Events that arrive before the run reaches the wait are not buffered.

  • Retries: a journaled step is retried on failure, 3 attempts by default, with exponential backoff from 1 s plus jitter, up to 1 hour. A step is not retried after a timeout or when it runs out of CPU or memory.
  • At-least-once: if a worker dies after a side effect but before the journal write, the step runs again. For payments and emails, pass the per-attempt idempotency key (<run_id>:<step>:<attempt>) to the other system.
  • Data and state: data moves between nodes as JSON. Shared run state is in ctx.flow.state, and ctx.user holds the verified caller identity (id, role). The caller cannot change it through the input.
  • Operate runs: on the Runs page you can follow each step, retry and error, retry a failed run (the journal prefix is kept), or cancel an active one. Cancelling (or failing) a run also cancels the child runs it started with Run flow.

Flows have no built-in rollback of finished steps. Model a saga yourself: after a step that can fail, branch with a Condition to a compensation path such as cancelling the order, refunding or restoring stock. A Wait for event with a timeout lets a run wait for a payment and compensate if it never arrives.

Sleeping and waiting runs hold no worker and do not count towards your concurrent runs, so a flow can last up to your plan’s run timeout (the longest single sleep is 1 day on Free, 7 on Go and 30 on Pro). Split very long processes into child flows with Run flow.

A flow with an HTTP trigger is called at /flows/v1/<name> with the same credentials as the Data API. A user token runs the flow as that user; the publishable key alone runs it as anon.

  • Synchronous (default): waits for the result, 10 s by default and up to 30 s with waitMs. A finished run answers with status and output; if it is still going you get its run_id and a running status.
  • Asynchronous: answers at once with the run_id; read it later with getRun.

The flows member comes from the Cloud package @potalab/base-cloud-sdk-flows:

import { createClient } from "@potalab/base"
import { withFlows } from "@potalab/base-cloud-sdk-flows"
const base = withFlows(createClient({ url, key }))
// sync
const { data, error } = await base.flows.invoke("place-order", { cartId, addressId })
console.log(data?.status, data?.output)
// async, then poll
const started = await base.flows.invoke("place-order", { cartId, addressId }, { async: true, idempotencyKey: "cart-42" })
const run = await base.flows.getRun(started.data!.run_id)

invoke and getRun return { data, error } and do not throw. The same idempotencyKey on the same flow returns the same run. A user can read only the runs it started; the secret key sees every run of the project.

The same call over HTTP:

Terminal window
curl -X POST "$API_URL/flows/v1/place-order?async=1" \
-H "apikey: $PUBLISHABLE_KEY" \
-H "Authorization: Bearer $USER_JWT" \
-H "Idempotency-Key: cart-42" \
-H "Content-Type: application/json" \
-d '{"cartId": "c_1", "addressId": "a_1"}'
curl "$API_URL/flows/v1/runs/<run_id>" \
-H "apikey: $PUBLISHABLE_KEY" -H "Authorization: Bearer $USER_JWT"
Limit Free Go Pro
Flows per project 1 10 50
Nodes per flow 5 20 50
Steps per run 50 200 1,000
Concurrent runs per project 2 10 50
Runs per month 1,000 20,000 300,000
Steps per month 5,000 200,000 3,000,000
Shortest cron interval 15 min 5 min 1 min
Step timeout 10 s 30 s 60 s
Longest sleep 1 day 7 days 30 days
Run history kept 3 days 7 days 30 days
  • Over the number of flows or nodes, a deploy answers 402 plan_limit_exceeded. Past the monthly runs or steps, a new trigger answers 402; runs already started finish.
  • Extra concurrent runs wait in the queue and start as others finish; they never fail. Runs that are waiting for an event or asleep do not count as concurrent.
  • A project can hold at most 10,000 queued runs by default. Over that, a new trigger is refused with 429 queue_full. Refused triggers (quota, queue full, missing identity) are listed under Runs → Triggers not run for 7 days.
  • Image, video and audio nodes depend on the plan: images and audio need Go or Pro, video needs Pro. Otherwise the deploy answers 402 feature_not_in_plan.
  • Step output over 64 KB is moved to object storage, and a run journal is capped at 16 MB.