Skip to main content
A workflow’s context is an object provided by the route function. The context object provides:
  • Workflow APIs – functions for defining workflow steps.
  • Workflow Run Properties – request payload, request headers, and other metadata.
import { serve } from "@upstash/workflow/nextjs";

export const { POST } = serve(
  // 👇 the workflow context
  async (context) => {
    // ...
  }
);

Context Object Properties

requestPayload
object
The request payload passed to the workflow run via trigger() call.
headers
object
The request headers passed to the workflow run via trigger() call.
workflowRunId
string
The unique identifier of the current workflow run.
url
string
The public URL of the workflow endpoint.
failureUrl
string
The URL used for workflow failure callback.If a failure function is defined, this is the same as the workflow’s url.
env
object
The environment variables available to the workflow.
qstashClient
object
The QStash client instance used by the workflow endpoint.
label
srting | undefined
The label of the current workflow run, if set in client.trigger.

Context Object Functions

You can use the functions exposed by context object to define workflow steps.