this demo shows off how to use river with sveltekit. there are two examples:
- question asker: fully resumable ai sdk agent with a tool call
- character classifier: a basic example of a custom stream
- river
- sveltekit
- redis (whichever provider you prefer, upstash and railway are both great)
- openrouter
- runed
- bun
- tailwindcss
- ai sdk
-
clone the repo, then
cdintosveltekit-river-demo -
install deps:
bun i -
create a
.env.localfile and add the following env vars:
# railway and upstash are both great providers, or you can run it locally
REDIS_URL=redis://...
# get one from the openrouter dashboard
OPENROUTER_API_KEY=
# the password to protect your app
SECRET_APP_PASSWORD=my_very_secure_password
-
start the dev server:
bun dev -
test it out at: http://localhost:5173
used railway as the deployment example here because you can also setup a redis instance with private networking right next to it which is really convenient and it's stupid fast
-
create a railway account (if you don't have one) and then make a new project
-
create a new railway project in the dashboard, and then create the following resources:
- a redis instance
- an empty service
-
add your env vars to the empty service you just created. make sure to use the private redis url for your redis url, the rest can just be what you have locally
-
install the railway cli (if you don't have it), then login https://docs.railway.com/guides/cli
-
link this project to a railway project:
bun run link(script just callsrailway link) -
deploy the project to railway:
bun run deploy(script just callsrailway up) -
generate a domain for your project to access it in the railway dashboard (under service settings)