1
Install the SDK
2
Add your keys
Add your project’s API key and secret to Then declare both in Variables are private by default, so they never reach the browser. The API key lets your app start runs and save steps. The secret lets your app check that each call really comes from Nelkap. When you deploy, set the same two variables in your host’s settings. See environment variables in the SvelteKit docs.
.env.local:.env.local
src/env.ts, so SvelteKit can give them to your server code:src/env.ts
3
Write a workflow
Create
src/lib/server/nelkap.ts. Files in a server folder only run on the server, which keeps your keys out of the browser:src/lib/server/nelkap.ts
- The client takes your keys from
$app/env/private, where SvelteKit provides them. onboardUseris your workflow: an async function that takes the run’s payload, here a user ID.- Each
step.runsaves what its function returns. When the run picks up after the sleep, the profile step gives back its saved result instead of creating the profile again. step.sleeppauses the run for a day. Nothing runs in your app during that day.registerWorkflowstells Nelkap which workflows your app runs, as soon as the file is loaded.
createProfile and sendWelcomeEmail with your own functions.4
Add the route
Create a
+server.ts file at the path of your endpoint, and export a POST handler that passes each request to nelkap.handle:src/routes/api/nelkap/+server.ts
handle checks the secret, answers Nelkap at once, and runs the workflow in the background. If your app checks sign-in on every route, for example in hooks.server.ts, leave /api/nelkap out: handle checks Nelkap’s secret instead.5
Deploy
Deploy your app with its two environment variables, so Nelkap can reach the route over the internet. Your project’s endpoint must be the route’s exact URL, like
https://your-app.com/api/nelkap.6
Start a run
Start the workflow from any server code. Here, the sign-up page’s form action starts it once the user is created:
src/routes/sign-up/+page.server.ts
run returns as soon as Nelkap has the run, so the sign-up doesn’t wait for the workflow. Its second argument, user.id, is the run’s payload: Nelkap passes it to onboardUser.7
View the run
Open your project’s runs. The new run shows the profile step with what it returned, then sleeps. A day later, Nelkap calls your route again, the welcome email goes out, and the run completes.
Deploy on Vercel
On Vercel, your function can stop as soon as the response is sent. PasswaitUntil from @vercel/functions to keep the run going after handle answers:
src/routes/api/nelkap/+server.ts
maxDuration option. If a call reaches that limit, every step already saved is kept, and Nelkap calls your app again about five minutes later to go on from there.