Skip to main content

Quickstart Guide

This guide will walk you through creating your first durable workflow with Workflow DevKit. You’ll learn how to:
  • Install and configure Workflow DevKit
  • Write a simple workflow with steps
  • Handle errors and retries
  • Start and monitor workflow runs
This guide uses Next.js as an example, but Workflow DevKit works with SvelteKit, Nuxt, Astro, and other frameworks. See Framework Guides for other options.

Installation

1

Install the package

Install Workflow DevKit in your project:
2

Configure your framework

Add the Workflow plugin to your framework configuration.
Update your next.config.ts (or next.config.js):
next.config.ts
3

Initialize the runtime (Next.js only)

For Next.js, create an instrumentation.ts file in your project root:
instrumentation.ts
Make sure instrumentationHook is enabled in your next.config.ts:

Create Your First Workflow

Let’s build a simple user signup workflow that creates a user, sends a welcome email, and then sends a follow-up email after a delay.
1

Create a workflow file

Create a new file workflows/user-signup.ts:
workflows/user-signup.ts
Key concepts:
  • 'use workflow' marks the main workflow function
  • 'use step' marks individual steps that are automatically retried
  • Each step’s result is persisted before moving to the next step
  • sleep() pauses the workflow for a specified duration
2

Create an API route to start workflows

Create an API route to trigger your workflow:
Create app/api/signup/route.ts:
app/api/signup/route.ts
3

Start your development server

Run your development server:
4

Test your workflow

Trigger your workflow with a POST request:
cURL
You should receive a response like:
Check your server logs to see the workflow executing:

Understanding Steps and Workflows

Workflows vs Steps

  • Workflows ('use workflow') are the main orchestration functions
  • Steps ('use step') are individual units of work that can fail and retry

Automatic Retries

Steps automatically retry when they throw an error. By default, retries happen immediately, but you can customize this:
Error Types:
  • Regular Error: Retried immediately (default behavior)
  • RetryableError: Retried after a specified delay
  • FatalError: Not retried - workflow fails permanently

Monitoring Workflow Runs

You can check the status and result of a workflow run:
app/api/runs/[runId]/route.ts

Using sleep() for Delays

The sleep() function pauses workflow execution without blocking your server:
Supported duration formats:
  • Milliseconds: sleep(5000) or sleep('5000ms')
  • Seconds: sleep('30s')
  • Minutes: sleep('5m')
  • Hours: sleep('2h')
  • Days: sleep('7d')
  • Date objects: sleep(new Date('2026-12-31'))

Next Steps

Now that you’ve built your first workflow, explore more advanced features:

Webhooks & Hooks

Pause workflows and resume them via external callbacks

AI Workflows

Build durable AI agents with tool calling

Error Handling

Advanced retry strategies and error recovery

Streaming

Stream real-time updates from long-running workflows

Common Patterns

Pattern 1: Multi-Step API Orchestration

Pattern 2: Human-in-the-Loop

Pattern 3: Scheduled Tasks

Troubleshooting

Make sure you’ve:
  1. Added the framework plugin to your config
  2. Created instrumentation.ts (Next.js only)
  3. Enabled instrumentationHook in next.config (Next.js only)
  4. Restarted your development server
Steps only retry when they throw an error. Check that:
  • Your step function has 'use step' directive
  • The function is actually throwing an error (not returning it)
  • You’re not catching and suppressing errors
If you see “Cannot find module ‘workflow’”:
  1. Make sure you’ve installed the package: npm install workflow
  2. Restart your TypeScript server in your editor
  3. Clear your framework’s build cache and restart

Need Help?

Join the discussion on GitHub for community support