Skip to main content

Run durable workflows

Build workflows with the Workflow SDK that survive restarts, retry steps, sleep for days and wait on hooks, with every run traced in the dashboard.

Workflows lets your functions run long, multi-step work that survives failures: a step that fails is retried, a run can sleep for minutes or days, and it can pause until something outside calls back. Use it for signups, order pipelines, AI agents, or anything that outlasts one request.

Easel implements the same backend as Vercel Workflows, so an app built with the Workflow SDK runs unchanged. There's nothing to set up: no database to bring, and your functions are authenticated automatically. Workflows is in beta.

Write a workflow

Install the SDK and add it to your framework's config (here, Next.js):

npm i workflow
next.config.ts
import { withWorkflow } from "workflow/next";

export default withWorkflow({});

A workflow is a function marked "use workflow"; each step it calls is a function marked "use step":

workflows/user-signup.ts
import { sleep } from "workflow";

export async function handleUserSignup(email: string) {
  "use workflow";
  const user = await createUser(email);
  await sleep("1 day");
  await sendOnboardingEmail(user);
  return { userId: user.id };
}

async function createUser(email: string) {
  "use step";
  return { id: crypto.randomUUID(), email };
}

async function sendOnboardingEmail(user: { id: string }) {
  "use step";
  // ...
}

Start a run from any function:

app/api/signup/route.ts
import { start } from "workflow/api";
import { handleUserSignup } from "@/workflows/user-signup";

export async function POST(request: Request) {
  const { email } = await request.json();
  const run = await start(handleUserSignup, [email]);
  return Response.json({ runId: run.runId });
}

How runs work

  • Steps retry. A step that throws is retried, 3 times by default (set maxRetries on the step to change it). Throw FatalError to fail without retrying.
  • Sleeps cost nothing. sleep() suspends the run; no function runs while it waits.
  • Hooks wait for the outside. createHook() pauses until resumeHook(token, payload) is called, from a webhook handler for example. A hook's token is unique in your project and environment while it's live. experimental_minRetention keeps it claimed after the run ends, and experimental_force takes a token over from the run that holds it.
  • Streams. A step can write to getWritable(), and getRun(runId).getReadable() reads it live from anywhere.
  • Pinned to the deployment. A run keeps running the code of the deployment that started it, even after you deploy again.

Steps and resumes are delivered by Queues, so a workflow's functions show up in your invocations like any other.

See your runs

Open Workflows in your project's sidebar. Runs are listed newest first, with counts by status; search by workflow, run ID or hook token, filter by environment and time range, or turn on Live to watch new runs arrive.

Open a run to see its trace: each step, each retry attempt, each sleep and hook on one timeline. Select a span for its details, input, output and events. From a run you can:

  • Wake Up Sleep on a sleeping run, to continue it now.
  • Resolve Hook on a waiting hook, with a JSON payload, as resumeHook() would.
  • Re-run it with the same input, Re-enqueue it if it's stuck, or Cancel it. You can also cancel several from the list.
  • See its Events and its output Streams, live while it runs.
  • Jump to its function logs with View Logs.

Encryption

Run data (inputs, outputs, errors, hook payloads and streams) is encrypted before it leaves your function, with a key unique to each run, as on Vercel. Your code doesn't change, and Easel only stores the encrypted bytes. In the dashboard, payloads show as Encrypted until you choose Decrypt on a run.

Retention and limits

A run's inputs, outputs, streams and trace are kept while it runs and then for your plan's retention period: 1 day on Hobby, 7 days on Pro. The run stays listed for 30 days after that, without its data. A run can have up to 25,000 events and 10,000 steps, and each payload can be up to 50 MB.

Pricing

Workflows bill three ways, at Vercel's rates: Workflow Events (each state change of a run or step), Workflow Data Written, and on Pro, Workflow Data Retained. Each plan includes 50,000 events and 1 GB written a month. See Pricing for the rates. The functions that run your steps bill like any other function.