Skip to content

Cloudflare Durable Objects

Deploy on Cloudflare Durable Objects when you want one isolated Arivie instance per owner with sub-second cold starts and idle survival — the deploy target RFC-002 §4.11.4 budgets as < 1 s cold, < 200 ms warm. The Worker routes POST /api/arivie to a named DO stub; model keys and DATABASE_URL come from Worker env bindings, not process.env.

Deploy targets and cold-start budgets

src/worker.ts
/* SPDX-License-Identifier: Apache-2.0 */
import { ArivieDO } from "./do";
import type { ArivieWorkerEnv } from "../arivie.config";
export { ArivieDO };
export default {
async fetch(
request: Request,
env: ArivieWorkerEnv & { ARIVIE_DO: DurableObjectNamespace },
): Promise<Response> {
const url = new URL(request.url);
if (url.pathname !== "/api/arivie") {
return new Response("with-cloudflare-do — POST /api/arivie", { status: 200 });
}
if (request.signal.aborted) {
return new Response("client disconnected", { status: 499 });
}
const id = env.ARIVIE_DO.idFromName("default");
const stub = env.ARIVIE_DO.get(id);
return stub.fetch(request);
},
};
Terminal window
cd arivie && pnpm install
pnpm --filter with-cloudflare-do build # wrangler deploy --dry-run
wrangler dev
curl -X POST http://127.0.0.1:8787/api/arivie -H 'Content-Type: application/json' -d '{"prompt":"How many customers?"}'

Canonical tree: arivie/examples/with-cloudflare-do/.