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
Configure your framework
Add the Workflow plugin to your framework configuration.
- Next.js
- SvelteKit
- Nuxt
Update your
next.config.ts (or next.config.js):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.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
Create an API route to start workflows
Create an API route to trigger your workflow:
- Next.js App Router
- Next.js Pages Router
- SvelteKit
Create
app/api/signup/route.ts:app/api/signup/route.ts
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 delayFatalError: 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)orsleep('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
Workflow not starting
Workflow not starting
Make sure you’ve:
- Added the framework plugin to your config
- Created
instrumentation.ts(Next.js only) - Enabled
instrumentationHookin next.config (Next.js only) - Restarted your development server
Steps not retrying
Steps not retrying
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
Module not found errors
Module not found errors
If you see “Cannot find module ‘workflow’”:
- Make sure you’ve installed the package:
npm install workflow - Restart your TypeScript server in your editor
- Clear your framework’s build cache and restart
Need Help?
Join the discussion on GitHub for community support