Framework Integrations
For users: If you want to use Workflow SDK with an existing framework, see Getting Started. This page is for framework authors.
This guide uses Bun as a concrete example, but the same build and routing model applies to other JavaScript frameworks and runtimes.
Read How the Directives Work first if you are not familiar with the three compiler modes.
Integration shape
A framework integration has two responsibilities:
- Build time: transform workflow and step code, register the steps, and generate the combined flow handler.
- Runtime: expose the generated flow and webhook handlers as HTTP routes.
Steps do not have their own HTTP route. A queued step invocation contains stepId and stepName and is delivered to the flow handler on the workflow queue. The handler executes the registered step in the full host runtime, then replays the workflow in its sandboxed VM.
Example: Bun integration
Generate the bundles
The standalone Workflow CLI scans workflows/ and creates the combined flow handler, an internal step registration module, and the webhook handler.
The default output is:
/.well-known/workflow/v1/flow.mjs: the combined workflow and step queue consumer/.well-known/workflow/v1/__step_registrations.mjs: an internal module imported byflow.mjs; do not route to it/.well-known/workflow/v1/webhook.mjs: webhook delivery
Production integrations should extend BaseBuilder from @workflow/builders so they can participate in the framework's build, watch, and routing lifecycle.
Add the app-code transform
Applying the step-mode transform to application code gives it the workflow IDs used by start() and prevents accidental direct workflow execution. (Earlier releases used a separate client mode for this; it merged into step in 5.0.)
Activate the plugin in bunfig.toml:
Expose the HTTP routes
Only the combined flow handler and webhook handler are routable:
Runtime routes
Combined flow endpoint
Route: POST /.well-known/workflow/v1/flow
The handler consumes every workflow queue message. Depending on the payload and event log, it can:
- Start or replay workflow orchestration in the sandboxed VM.
- Execute a queued step in the host runtime.
- Continue replay inline after a step completes.
- Resume a run after a hook, webhook, sleep, retry, or recovery event.
Webhook endpoint
Route: /.well-known/workflow/v1/webhook/:token
This handler delivers data to createWebhook(). Its generated file structure varies by framework; for example, Next.js uses webhook/[token]/route.js.
Building with BaseBuilder
Use createCombinedBundle() so the flow bundle imports the generated step registrations. Calling createWorkflowsBundle() and createStepsBundle() independently does not create a complete runtime route.
If workflows import sibling workspace packages, set projectRoot to the smallest directory containing all imported packages.
Your integration can expose physical files, virtual modules, or framework-native routes. In every case, the step registration module is a dependency of the flow handler, not a route of its own.
Vercel queue configuration
On Vercel, configure the flow function as the sole queue consumer. getWorkflowQueueTrigger() handles the optional queue namespace.
The generated trigger listens to one topic family:
Both orchestration messages and step messages use this topic family. A step message is distinguished by its payload, not by a second topic or function.
If you construct the trigger yourself, set no maxConcurrency on it: a spec 9 run's orchestrator messages are kept to one invocation at a time per run by the Vercel World. isSequentialReplaysEnabled() is deprecated and always returns false; remove any maxConcurrency: 1 that depended on it.
Security
On Vercel, the flow handler uses queue consumer security. For self-hosted worlds, protect the flow and webhook routes with the authentication, network controls, and rate limits appropriate to your queue transport.
Testing an integration
After a build, verify that:
- the flow handler exists and imports or embeds the step registration bundle;
- the webhook handler exists;
- no step HTTP route or step queue trigger is generated;
- the flow function has the workflow queue trigger and the required maximum duration;
- starting a workflow executes a real step and resumes the workflow.
The flow route exposes a lightweight direct health mode:
For an end-to-end queue check, use healthCheck().