serve
method to define an endpoint that serves a workflow. It provides a context object that you use to create all of your workflow’s steps.
For example, in a Next.js or FastAPI app:
serve
method supports multiple frameworks and platforms. See all supported platforms here.
failureUrl
failureUrl
option to specify a URL your workflow will call if it exhausted all retries and fails.
failureUrl
and use client.trigger
to start your workflow, you should pass failureUrl
in client.trigger
too.body
field.
The default value is undefined
, meaning no failure URL is called.
failureFunction
failureFunction
to define a function that’s executed when your workflow exhausts all its retries and fails.
failureFunction
and use client.trigger
to start your workflow, you should pass useFailureFunction: true
in client.trigger
.failureUrl
and failureFunction
are provided, the failure function takes precedence and the value of failureUrl
is ignored.
By default, failureFunction
is undefined
, meaning that no function is executed on failure.
retries
verbose
parameter.
The default value is 3.
flowControl
rate
and period
options. To limit the maximum number of concurrent requests, use the parallelism
option within the flowControl
settings. See the flow control section for more details.
rate
or parallelism
if you only need one of the two.
By default, there is no rate per second or parallelism limit.
verbose
eventType
can be:
ENDPOINT_START
each time the workflow endpoint is calledRUN_SINGLE
or RUN_PARALLEL
when step(s) are executedSUBMIT_STEP
when a single step is executedSUBMIT_FIRST_INVOCATION
when a new workflow run startsSUBMIT_CLEANUP
when a workflow run finishesSUBMIT_THIRD_PARTY_RESULT
when a third-party call result is received (see context.call
)initialPayloadParser
initialPayloadParser
option:
url
serve
method needs to know where your endpoint is hosted.
Typically, your workflow infers this using the request.url
field.
However, if you use a proxy or a local tunnel for development, you may want to override the URL inferred from request.url
:
url
is undefined
, and the URL is inferred from request.url
.
baseUrl
url
option is the baseUrl
option. While url
replaces the entire URL inferred from request.url
, baseUrl
only changes the base of the URL:
baseUrl
is undefined
.
If you have multiple endpoints and you don’t want to set baseUrl
in every single one, you can set the UPSTASH_WORKFLOW_URL
environment variable to apply baseUrl
across your entire application.
Setting this environment variable is especially useful during local development. In production, baseUrl
or UPSTASH_WORKFLOW_URL
are not necessary.
qstashClient
qstashClient
option allows you to pass a QStash Client explicitly. This can be helpful when using multiple QStash clients in the same project with different environment variables.
qstashClient
is initialized as:
receiver
QSTASH_CURRENT_SIGNING_KEY
and QSTASH_NEXT_SIGNING_KEY
are set. If you want to turn off the Receiver, remove these environment variables or pass receiver: undefined
in the options. Note that this will skip any verification that requests are coming from QStash and allow anyone to start your workflow.
env
process.env
to initialize the QStash client and the receiver (if the two environment variables are set). If process.env
doesn’t exist, the SDK won’t be able to access the environment variables. In this case, you can either pass qstashClient
and receiver
options or use the env
option.
If you pass env
, this env
will be used instead of process.env
:
disableTelemetry
disableTelemetry
to false
if you wish to disable this behavior.