start()

Start/enqueue a new workflow run.

import { start } from 'workflow/api';
import { myWorkflow } from './workflows/my-workflow';

const run = await start(myWorkflow); 

API Signature

Parameters

This function has multiple signatures.

Signature 1

NameTypeDescription
workflowWorkflowFunction<TArgs, TResult> | WorkflowMetadataThe imported workflow function to start.
argsTArgsThe arguments to pass to the workflow (optional).
optionsStartOptionsThe options for the workflow run (optional).

Signature 2

NameTypeDescription
workflowWorkflowMetadata | WorkflowFunction<[], TResult>
optionsStartOptions

StartOptions

NameTypeDescription
deploymentIdstringThe deployment ID to use for the workflow run.

Returns

Returns a Run object:

NameTypeDescription
runIdstringThe ID of the workflow run.
cancel() => Promise<void>Cancels the workflow run.
statusPromise<"pending" | "running" | "completed" | "failed" | "paused" | "cancelled">The status of the workflow run.
returnValuePromise<TResult>The return value of the workflow run. Polls the workflow return value until it is completed.
workflowNamePromise<string>The name of the workflow.
createdAtPromise<Date>The timestamp when the workflow run was created.
startedAtPromise<Date | undefined>The timestamp when the workflow run started execution. Returns undefined if the workflow has not started yet.
completedAtPromise<Date | undefined>The timestamp when the workflow run completed. Returns undefined if the workflow has not completed yet.
readableReadableStream<any>The readable stream of the workflow run.
getReadable<R = any>(options?: WorkflowReadableStreamOptions | undefined) => ReadableStream<R>Retrieves the workflow run's default readable stream, which reads chunks written to the corresponding writable stream getWritable .

Good to Know

  • The start() function is used in runtime/non-workflow contexts to programmatically trigger workflow executions.
  • This is different from calling workflow functions directly, which is the typical pattern in Next.js applications.
  • The function returns immediately after enqueuing the workflow - it doesn't wait for the workflow to complete.
  • All arguments must be serializable.

Examples

With Arguments

import { start } from 'workflow/api';
import { userSignupWorkflow } from './workflows/user-signup';

const run = await start(userSignupWorkflow, ['user@example.com']); 

With StartOptions

import { start } from 'workflow/api';
import { myWorkflow } from './workflows/my-workflow';

const run = await start(myWorkflow, ['arg1', 'arg2'], { 
  deploymentId: 'custom-deployment-id'
});