Skip to main content
Sign In
Platforms

Deploying to Cloudflare Workers

Run RivetKit on Cloudflare Workers with the WebAssembly runtime.

Cloudflare Workers run RivetKit through the WebAssembly runtime. Use the public @rivetkit/rivetkit-wasm package, pass the bindings through setup({ wasm }), and use remote SQLite.

Steps

Prerequisites

Install Packages

npm install rivetkit @rivetkit/rivetkit-wasm
npm install --save-dev wrangler

Configure Wrangler

Set your Rivet connection values as Worker variables. The pool name must match the serverless runner configured in Rivet.

name = "rivetkit-cloudflare"
main = "src/index.ts"
compatibility_date = "2025-04-01"
compatibility_flags = ["nodejs_compat"]

[vars]
RIVET_ENDPOINT = "https://api.rivet.dev"
RIVET_NAMESPACE = "your-namespace"
RIVET_POOL = "cloudflare-workers"
RIVET_TOKEN = "sk_..."
RIVET_PUBLIC_ENDPOINT = "https://your-namespace:pk_...@api.rivet.dev"

Create the Worker

This example uses raw SQL to keep the runtime setup visible. When runtime: "wasm" is used, unset SQLite defaults to remote SQLite, and sqlite: "local" is rejected.

Deploy

npx wrangler deploy

After deploy, set the Worker URL with the /api/rivet path as the serverless runner URL in Rivet.

Runtime Notes

  • Use runtime: "wasm" in setup(...) for Workers. You can also set RIVETKIT_RUNTIME=wasm in environments where the registry config does not set runtime.
  • Pass wasm: { bindings, initInput } explicitly from @rivetkit/rivetkit-wasm.
  • Use remote SQLite on Workers. Leaving SQLite unset with runtime: "wasm" selects remote SQLite automatically.
  • Keep RIVET_PUBLIC_ENDPOINT pointed at the client-facing Rivet endpoint. Register the Worker URL separately as the serverless runner URL.
  • Local Workers runtimes must support outbound WebSockets for the Rivet envoy connection.