Cloudflare Durable Objects
When to use this
Section titled “When to use this”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.
Architecture
Section titled “Architecture”Code snippet
Section titled “Code snippet”/* 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); },};Run it
Section titled “Run it”cd arivie && pnpm installpnpm --filter with-cloudflare-do build # wrangler deploy --dry-runwrangler devcurl -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/.