Skip to main content
Quickstart

Cloudflare Workers Quickstart

Set up a Rivet project locally targeting Cloudflare Workers.

Set up a Rivet project locally that runs on Cloudflare Workers. The @rivetkit/cloudflare-workers package wires the WebAssembly runtime for you.

Prefer to start from a complete project? See the runnable hello-world-cloudflare-workers example (with Hono and raw router variants).

Steps

Install Packages

npm install rivetkit @rivetkit/cloudflare-workers
npm install --save-dev wrangler

Configure Wrangler

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

The nodejs_compat flag is required so the runtime can read its connection config from process.env.

Create the Worker

createHandler serves the Rivet manager API on /api/rivet. Pick how you want to handle your own routes:

  • Default: Rivet handles everything.
  • Hono: Mount a Hono app for your routes (npm install hono).
  • Raw: Provide a fetch and route requests yourself.

Run Locally

Start Rivet. The CLI runs the local engine and spawns wrangler dev for you:

npx @rivetkit/cli dev --provider cloudflare

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.

Connect To The Rivet Actor

This code can run either in your frontend or within your backend. It connects directly to the local engine on http://localhost:6420:

Deploy

Ready to ship? See Deploying to Cloudflare Workers.