Steps

Overview

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.
api/workflow/route.ts
import { serve } from "@upstash/workflow/nextjs";export const { POST } = serve(  // πŸ‘‡ the workflow context  async (context) => {    // ...  });
main.py
from fastapi import FastAPIfrom upstash_workflow.fastapi import Servefrom upstash_workflow import AsyncWorkflowContextapp = FastAPI()serve = Serve(app)@serve.post("/api/example")async def example(context: AsyncWorkflowContext[str]) -> None: ...

Context Object Properties

requestPayloadpathobject

The request payload passed to the workflow run via trigger() call.

headerspathobject

The request headers passed to the workflow run via trigger() call.

workflowRunIdpathstring

The unique identifier of the current workflow run.

urlpathstring

The public URL of the workflow endpoint.

failureUrlpathstring

The URL used for workflow failure callback.

If a failure function is defined, this is the same as the workflow's url.

envpathobject

The environment variables available to the workflow.

qstashClientpathobject

The QStash client instance used by the workflow endpoint.

labelspathstring[]

The labels attached to the current workflow run, if set in client.trigger. Defaults to an empty array when no label was set.

labelpathstring | undefineddeprecated

Deprecated. Use labels instead. When a run has multiple labels, this only returns the first one.

Context Object Functions

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

Loading search…