Create the Durable Object class and type-safe client factory for a set of workflow definitions.
createDurableWorkflows is the main factory function that wires your workflow definitions into a production-ready execution engine running on Cloudflare Durable Objects. It returns two exports: Workflows (the Durable Object class) and WorkflowClient (a type-safe client factory).
function createDurableWorkflows<const W extends WorkflowRegistry>( workflows: W, options?: CreateDurableWorkflowsOptions): CreateDurableWorkflowsResult<W>
A record mapping workflow names to WorkflowDefinition objects created with
Workflow.make. The object keys become the workflow names used when
dispatching via the client. Use as const to preserve literal key types for
full type safety.
const workflows = { processOrder: processOrderWorkflow, sendNotification: notificationWorkflow,} as const;
Event tracker configuration. When provided, the engine emits workflow
lifecycle events (started, completed, failed, paused, step events) to the
specified HTTP endpoint. When omitted, a no-op tracker is used and no
events are emitted.
Recovery configuration controlling how the engine detects and recovers
stale workflows after infrastructure interruptions. All fields are
optional and fall back to defaults.
Automatic data purging configuration. When provided, the engine schedules
deletion of all workflow data after the workflow reaches a terminal state
(completed, failed, cancelled). When omitted, data is retained
indefinitely.
Time to wait after a terminal state before purging. Allows external
systems to query final results before data is deleted. Accepts a
duration string ("5 minutes") or milliseconds.
The Durable Object class. Export this from your worker entry point and
register it in your wrangler.jsonc configuration. This class extends
Cloudflare’s DurableObject and handles all lifecycle events (RPC calls,
alarms, recovery).
Create a client instance from a Cloudflare Durable Object namespace
binding (e.g., env.WORKFLOWS). Returns a WorkflowClientInstance
with all client methods as Effects.
The type-safe request object passed to run and runAsync. The workflow field must be a key from your registry, and input is automatically typed to match that workflow’s input type.
type WorkflowRunRequest = { workflow: keyof W; // one of your registered workflow names input: WorkflowInput<W[K]>; // type-safe input for that workflow execution?: ExecutionOptions;}
Custom instance ID suffix. The final Durable Object ID will be
{workflow}:{id}. Use this to ensure idempotency — if a workflow
with this ID already exists, the existing instance is used. If
omitted, a random UUID is generated.