upstash/workflow-js / skills
upstash-workflow-js
UnverifiedLightweight 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 2.2 KB |
| agents.md | markdown | 6.7 KB |
| basics/client.md | markdown | 4.1 KB |
| basics/context.md | markdown | 5.1 KB |
| basics/serve.md | markdown | 2.4 KB |
| features/flow-control.md | markdown | 3.9 KB |
| features/invoke.md | markdown | 2.6 KB |
| features/retries-failures-reliability.md | markdown | 6.3 KB |
| features/wait-for-event.md | markdown | 2.8 KB |
| features/webhooks.md | markdown | 2.5 KB |
| how-to/local-dev.md | markdown | 3.2 KB |
| how-to/middleware.md | markdown | 4.7 KB |
| how-to/migrations.md | markdown | 4.8 KB |
| how-to/realtime.md | markdown | 4.8 KB |
| rest-api.md | markdown | 6.6 KB |
| troubleshooting.md | markdown | 4.8 KB |
basics/serve.md
View on GitHubThis 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`.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 471k | Updated | Claude CodeCodex | Verified | Install |
| 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: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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 available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |