Skip to content
brought to you byVoidZero

Workflows ​

Suppose you want to publish a blog post tomorrow morning. Your route can start a Workflow and return an ID right away. Cloudflare keeps track of when to wake the Workflow and which steps it has already completed.

Define a Workflow ​

Create workflows/publish-post.ts and export the definition as the default. The example uses Zod to describe the JSON our callers send. Install it with vp add zod to follow along. Callers supply a timestamp as a string, and the Workflow receives a Date.

ts
// workflows/publish-post.ts
import { defineWorkflow } from 'void/workflows';
import { z } from 'zod';

export default defineWorkflow({
  params: z.object({
    slug: z.string().min(1),
    title: z.string().min(1),
    publishAt: z.iso.datetime().transform((value) => new Date(value)),
  }),
  async run({ payload: post }, step, { env }) {
    await step.sleepUntil('publication time', post.publishAt);
    await step.do('publish post', () => env.KV.put(`posts:${post.slug}`, post.title));
    return { slug: post.slug };
  },
});

When the timer expires, the second step writes the title to KV. If the write fails, Cloudflare can retry that step. Keep side effects inside step.do() so that resuming the Workflow skips work that already completed. Cloudflare step API

Void gives env the same binding types you get in a route. Run void prepare to pick up your app's bindings. You can also use void/kv and void/db inside a step. Each step attempt gets its own D1 session. If it needs a bookmark, call setSession({ bookmark }) before its first query.

Start an instance from a route ​

Import the default export and call create(). Let's publish a post ten minutes from now.

ts
// routes/api/publish.ts
import { defineHandler } from 'void';
import PublishPost from '../../workflows/publish-post';

export const POST = defineHandler(async () => {
  const instance = await PublishPost.create({
    params: {
      slug: 'hello-void',
      title: 'Hello, Void!',
      publishAt: new Date(Date.now() + 10 * 60_000).toISOString(),
    },
  });
  return { id: instance.id };
});

Save the ID if you want to check on the post later. await PublishPost.get(id) gives you the instance. Its status() method tells you whether it is waiting, has completed, or has failed.

Validate params ​

The same JSON works from a route, a raw Worker binding, the Cloudflare dashboard, or the REST API. Void applies the schema at the start of run. In the example above, an invalid timestamp fails the instance with a WorkflowParamsError before the timer starts. A successful create() means Cloudflare created the instance. If your HTTP endpoint needs to respond with a 400, validate the request in the route too.

Use any Standard Schema validator, including Zod, Valibot, or ArkType. Keep transforms deterministic because Cloudflare can run the entrypoint again when it resumes an instance. For TypeScript-only checks, omit params and pass your input type to defineWorkflow<MyParams>().

Start a batch ​

Use { instances } when each post has its own params or ID. Use { count, params } to start several instances with the same input. Both forms accept up to 100 instances and return { created, errors }. Check errors for entries Cloudflare could not create. Each error includes its position in the batch. Workflow API reference

Native Workflow classes ​

If you already have a class that extends Cloudflare's WorkflowEntrypoint, you can keep its run(event, step) implementation. For example, if your class lives in src/import-posts.ts, register it in workflows/import-posts.ts.

ts
// workflows/import-posts.ts
import { defineWorkflowEntrypoint } from 'void/workflows';
import { ImportPosts } from '../src/import-posts';

export default defineWorkflowEntrypoint({ class: ImportPosts });

The default export has the same create(), createBatch(), and get() methods. TypeScript reads the payload type from the class's run method.

Names and bindings ​

Void turns workflows/publish-post.ts into the WORKFLOW_PUBLISH_POST binding and the PublishPostWorkflow class. On Cloudflare the Workflow is named <worker-name>_publish-post. Instances belong to that name. Before moving a deployed Workflow, run void info and copy the suggested name into its definition. New and existing instances will still belong to the same Workflow.

Keep workflows/ at the project root, including when you set sourceDir. A path like workflows/posts/publish.ts uses the name posts-publish. A filename starting with a digit, such as 2026-report.ts, generates the class Workflow2026Report. Void skips files and directories whose names start with _, so you can keep step helpers beside their Workflow. Use ES modules for both. Use .mts or .mjs in a CommonJS project and .tsx or .jsx for JSX. If your tsconfig has an explicit include list, add workflows.

The definition's name must be a static string containing an ASCII letter or digit. To use an existing account-wide Workflow name or shorten a generated name that exceeds 64 characters, set the name on its binding.

ts
// void.config.ts
import { defineConfig } from 'void/config';

export default defineConfig({
  cloudflare: {
    workflows: [
      { binding: 'WORKFLOW_PUBLISH_POST', class_name: 'PublishPostWorkflow', name: 'publish-post' },
    ],
  },
});

If your config already declares the Workflow in cloudflare.exports, use the generated class name as the export key. Void uses the name and settings from that export.

Deploy to Cloudflare ​

Workflows run locally in native Void apps targeting Cloudflare Workers. Deploy to your Cloudflare account with void deploy --platform cloudflare. Workers Free includes Workflows. Cloudflare Workflows limits

Recurring Workflow schedules, more than 1,024 steps, concurrency above 100, or default retention longer than 3 days require Workers Paid. Paid accounts support up to 25,000 steps and 30 days of retention. To keep completed or failed instances longer, set default_retention.success_retention or default_retention.error_retention to a duration like "7 days" or a whole number of milliseconds. For paid settings, your API token needs Account Settings: Read to check the account limits and Workers Scripts: Edit to publish.

If Cloudflare cannot stage a Workflow addition, rename, or removal, review the change and run void deploy --platform cloudflare --atomic. The new version will receive traffic before Void checks readiness.

You can publish the same project's static assets to a Void platform. Build the app, then run void deploy --platform void --dir dist/client. You can also set inference.appType to static or spa and run void deploy --platform void. Set inference.outputDir if you use a different public output directory.