עברית 📰 Blog
← Back to Blog
AI Tools

Running stateful AI at the edge with Cloudflare Workers and Durable Objects

Masterphub Team
November 5, 2026

Share this article

Running stateful AI at the edge with Cloudflare Workers and Durable Objects

Cloudflare Workers let you run JavaScript close to the user. The code runs in a lightweight sandbox that spins up in milliseconds. When you add Durable Objects, each object holds its own state and can be reached from any Worker instance. This combination gives you a way to build AI services that keep context without a traditional server.

The camelAI project shows how to wrap a language model behind a Worker endpoint. The request arrives, the Worker forwards the prompt to the model, and the response is sent back. Because the Worker lives at the edge, latency drops dramatically compared to a central cloud server.

Durable Objects become useful when the AI needs to remember a conversation. Each user can be assigned a unique object. The object stores the last few messages, so the next request can include that history. The state lives in Cloudflare’s global network, not on a single VM. This design avoids the need for a separate database or session store.

From a developer’s view, the code stays small. A Worker script handles HTTP, calls the model API, and reads or writes to the Durable Object. Cloudflare takes care of scaling. If traffic spikes, more Workers start automatically, and the objects stay consistent because Cloudflare routes all calls for a given key to the same instance.

Security is built in. Workers run in isolation, and Durable Objects only expose the methods you define. You can restrict access with API tokens or signed URLs. This reduces the attack surface compared to a monolithic server.

For marketplace creators on masterphub.io, this pattern means you can sell AI prompts that need context without worrying about backend ops. A buyer can deploy the Worker, point a domain to it, and start using the prompt instantly. The edge runtime handles the heavy lifting.

In short, Cloudflare Workers give you fast, global compute. Durable Objects add persistent state. Together they let you run real‑time, stateful AI applications at the edge, removing the need for traditional servers.

We turned this idea into a ready-to-use skill on Masterphub: "Edge chat memory with Cloudflare Workers".

Share this article