Supabase Functions Quickstart
Set up a Rivet project locally targeting Supabase Edge Functions.
Set up a Rivet project locally that runs on Supabase Edge Functions. The @rivetkit/supabase package wires the WebAssembly runtime for you.
Prefer to start from a complete project? See the runnable hello-world-supabase-functions example.
Steps
Prerequisites
- Node.js
- Supabase CLI
- Docker, for Supabase’s local Edge Runtime
The CLI runs the local Rivet engine as a bundled native binary, so Docker is only needed for Supabase itself. A Supabase project is only needed to deploy.
Create the Function
npx supabase functions new rivet
Add the packages used by the function:
npm install rivetkit @rivetkit/supabase
Configure the Function
Call serve from @rivetkit/supabase. It loads the WebAssembly runtime and serves the Rivet handler.
import { actor } from "rivetkit";
import { serve, setup } from "@rivetkit/supabase";
const counter = actor({
state: { count: 0 },
actions: {
increment: (c, amount = 1) => {
c.state.count += amount;
return c.state.count;
},
},
});
// `setup` returns a typed registry, so a client can type itself with
// `typeof registry`.
export const registry = setup({ use: { counter } });
await serve(registry);
Run Locally
Start Rivet. The CLI runs the local engine, spawns supabase functions serve for you, and populates the connection values:
npx @rivetkit/cli dev --provider supabase
Visit http://localhost:6420 in your browser (or point your AI agent at it) to open the Rivet developer tools and inspect your actors live.
Call the Actor
Connect to your actor from a client. This connects directly to the local engine on http://localhost:6420:
import { createClient } from "rivetkit/client";
import type { registry } from "./supabase/functions/rivet/index";
const client = createClient<typeof registry>("http://localhost:6420");
const counter = client.counter.getOrCreate(["my-counter"]);
const count = await counter.increment(3);
console.log("New count:", count);
See the JavaScript client documentation for more information.
Deploy
Ready to ship? See Deploying to Supabase Functions.