Skip to content

upstash/workflow-js / skills

upstash-workflow-js

Unverified

Lightweight guidance for using the Upstash Workflow SDK to define, trigger, and manage workflows. Use this Skill whenever a user wants to create workflow endpoints, run steps, or interact with the Upstash Workflow client.

FileKindSize
SKILL.mdskill md2.2 KB
agents.mdmarkdown6.7 KB
basics/client.mdmarkdown4.1 KB
basics/context.mdmarkdown5.1 KB
basics/serve.mdmarkdown2.4 KB
features/flow-control.mdmarkdown3.9 KB
features/invoke.mdmarkdown2.6 KB
features/retries-failures-reliability.mdmarkdown6.3 KB
features/wait-for-event.mdmarkdown2.8 KB
features/webhooks.mdmarkdown2.5 KB
how-to/local-dev.mdmarkdown3.2 KB
how-to/middleware.mdmarkdown4.7 KB
how-to/migrations.mdmarkdown4.8 KB
how-to/realtime.mdmarkdown4.8 KB
rest-api.mdmarkdown6.6 KB
troubleshooting.mdmarkdown4.8 KB

basics/serve.md

View on GitHub
This documentation explains how to use `serve()` to expose workflows as HTTP endpoints.

## Core Concept

`serve()` turns an async route function into a workflow endpoint. When a request arrives, a workflow run is created, and the route function defines the execution logic using `context.run()`.

### Full Example With Inline Comments

```typescript
import { serve } from "@upstash/workflow/nextjs";
import { z } from "zod";
import { Client, Receiver } from "@upstash/qstash";
import { loggingMiddleware } from "@upstash/workflow";

type InitialPayload = { foo: string; bar: number };

const payloadSchema = z.object({ foo: z.string(), bar: z.number() });

export const { POST } = serve<InitialPayload>(
  async (context) => {
    const payload = context.requestPayload;
    await context.run("step-1", async () => `hello ${payload.foo}`);
  },
  {
    // Runs when the workflow fails after all retries
    failureFunction: async ({ context, failStatus, failResponse, failHeaders, failStack }) =>
      console.error(failResponse),

    // Hooks for step lifecycle, run lifecycle, and debug events
    middlewares: [loggingMiddleware],

    // Manually parse the initial request payload before workflow execution
    initialPayloadParser: (raw) => JSON.parse(raw),

    // Automatically validate + parse the request payload using Zod
    schema: payloadSchema,

    // Override the full URL used to schedule subsequent workflow steps
    url: "https://myapp.com/api/workflow",

    // Override only the base portion of the inferred URL (keeps the route path)
    baseUrl: "https://proxy-url.com",

    // Provide a custom QStash client
    qstashClient: new Client({ token: process.env.QSTASH_TOKEN! }),

    // Provide a custom QStash Receiver for verifying that requests come from QStash
    receiver: new Receiver({
      currentSigningKey: process.env.QSTASH_CURRENT_SIGNING_KEY!,
      nextSigningKey: process.env.QSTASH_NEXT_SIGNING_KEY!,
    }),

    // Override environment variables available inside workflow execution
    env: {
      QSTASH_URL: "https://qstash.upstash.io",
      QSTASH_TOKEN: process.env.QSTASH_TOKEN!,
    },

    // Output detailed execution logs to stdout
    verbose: true,

    // Disable anonymous telemetry for this workflow endpoint
    disableTelemetry: true,
  }
);
```

## Common Pitfalls

- **Incorrect URL inference** behind proxies or local tunnels—set `url` or `baseUrl`.
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall