Astro
Set up your first durable workflow in an Astro app and learn the core Workflow SDK concepts.
Create your Astro project
Create an Astro project in a new directory named my-workflow-app:
Enter the newly made directory:
Install workflow
Configure Astro
Add workflow() to your Astro config. This enables usage of the "use workflow" and "use step" directives.
workflow() accepts an options object:
| Option | Type | Default | Description |
|---|---|---|---|
sourcemap | boolean | 'inline' | 'linked' | 'external' | 'both' | 'inline' (dev) / false (prod) | Controls source maps on generated workflow bundles. Accepts the same values as esbuild's sourcemap option. Defaults to 'inline' in development and false in production (smaller function bundles, which helps stay under the Vercel 250 MB function size limit). Set it explicitly, or use the WORKFLOW_SOURCEMAP environment variable, to override in either environment. |
Set up IntelliSense for TypeScript (optional)
To enable helpful hints in your IDE, set up the workflow plugin in tsconfig.json:
Create your first workflow
Create a new file for our first workflow:
We'll fill in those functions next, but first review this code:
- We define a workflow function with the directive
"use workflow". Think of the workflow function as the orchestrator of individual steps. - The Workflow SDK's
sleepfunction allows us to suspend execution of the workflow without using up any resources. A sleep can be a few seconds, hours, days, or even months long.
Create your workflow steps
Define the missing functions.
Taking a look at this code:
- Business logic lives inside steps. When a workflow invokes a step, the workflow suspends while the step runs with full Node.js access. The combined handler may execute it inline; queued retries and continuations return through the same flow route.
- If a step throws an error, like in
sendWelcomeEmail, the step will automatically be retried until it succeeds (or hits the step's max retry count). - Steps can throw a
FatalErrorif an error is intentional and should not be retried.
We'll dive deeper into workflows, steps, and other ways to suspend or handle events in Foundations.
Create your route handler
To invoke your new workflow, we'll have to add your workflow to a POST API route handler, src/pages/api/signup.ts with the following code:
This route handler creates a POST request endpoint at /api/signup that will trigger your workflow.
Workflows can be triggered from API routes or any server-side code.
Run in development
To start your development server, run the following command in your terminal in the Vite root directory:
Once your development server is running, you can trigger your workflow by running this command in the terminal:
Check the Astro development server logs to see your workflow execute as well as the steps that are being processed.
Additionally, you can use the Workflow SDK CLI or Web UI to inspect your workflow runs and steps in detail.

Deploying to production
Workflow SDK apps currently work best when deployed to Vercel and need no special configuration.
To deploy your Astro project to Vercel, ensure that the Astro Vercel adapter is configured:
Additionally, check the Deploying section to learn how your workflows can be deployed elsewhere.
Troubleshooting
start() says it received an invalid workflow function
If you see this error:
Check both of these first:
- The workflow function includes
"use workflow". - Your
astro.config.mjsincludes theworkflow()integration.
See start-invalid-workflow-function for full examples and fixes.
Next steps
- Learn more about the Foundations.
- Check Errors if you encounter issues.
- Explore the API Reference.