<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/create-ai-workout-plans-with-cloudflare-durable-objects-zdsytopjd" -->

---
title: Create AI Workout Plans with Cloudflare Durable Objects
description: A developer walks through building an AI-powered workout template generator using Cloudflare Durable Objects paired with Vercel's AI SDK. The Durable Object...
canonical: https://daily.dev/posts/create-ai-workout-plans-with-cloudflare-durable-objects-zdsytopjd
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Create AI Workout Plans with Cloudflare Durable Objects | daily.dev
og:description: A developer walks through building an AI-powered workout template generator using Cloudflare Durable Objects paired with Vercel's AI SDK. The Durable Object...
og:url: https://daily.dev/posts/create-ai-workout-plans-with-cloudflare-durable-objects-zdsytopjd
og:image: https://api.daily.dev/og/posts/ZdSYtopJd.png
og:image:alt: Create AI Workout Plans with Cloudflare Durable Objects
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Create AI Workout Plans with Cloudflare Durable Objects

**[Frontend Masters](https://daily.dev/sources/frontendmasters)** · 10 min read · 0 upvotes · 0 comments

## Summary

A developer walks through building an AI-powered workout template generator using Cloudflare Durable Objects paired with Vercel's AI SDK. The Durable Object provides per-user SQLite storage and built-in WebSocket support, solving the earlier problem of losing in-flight AI generation results on page refresh. The post covers the DO class setup with Drizzle ORM for SQL access, WebSocket connection handling via a proxied API route, session creation and persistence, and pushing generation results to the browser in real time. Code excerpts show the DO definition, migration handling via blockConcurrencyWhile, sending WebSocket messages, and server functions that interact with the DO.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.master.dev/making-the-most-of-vercels-ai-sdk-with-cloudflare-durable-objects>

## Questions this post answers

### How can I persist AI generation results so they survive a page refresh in a web app?

Use a Cloudflare Durable Object per user, running the AI prompt inside the object and saving both the prompt and result to its dedicated SQLite storage. When generation finishes, push the result to the browser over a built-in WebSocket connection; on refresh, the client reconnects to the same Durable Object and queries SQLite for prior and current session data.

_daily.dev surfaces patterns like this for developers designing resilient, stateful AI-driven UIs._

### How do you set up a WebSocket connection with a Cloudflare Durable Object from a web app?

Expose an API route (or server route) that proxies the raw request to the Durable Object's fetch method, which checks for an Upgrade header of websocket, creates a WebSocketPair, calls ctx.acceptWebSocket on the server socket, and returns the client socket with a 101 status. The Durable Object can then broadcast messages to all connected sockets via ctx.getWebSockets().

_daily.dev helps developers wiring up real-time features track patterns like Durable Object WebSockets._

### Can I use Drizzle ORM with Cloudflare Durable Objects SQLite storage?

Yes, the drizzle-orm/durable-sqlite package provides a DrizzleSqliteDODatabase type that wraps a Durable Object's ctx.storage, letting you run type-safe SQL queries synchronously without async/await, since the underlying SQLite API inside a Durable Object is synchronous rather than promise-based.

_daily.dev keeps developers evaluating ORM options for edge storage informed on tools like this._

## Similar posts on daily.dev

- [Durable Objects on Cloudflare – Master.dev Blog](https://daily.dev/posts/durable-objects-on-cloudflare-master-dev-blog-zl8uewo5b) · Frontend Masters · 0 upvotes · 0 comments
- [Durable Objects in Dynamic Workers: Give each AI-generated app its own database](https://daily.dev/posts/durable-objects-in-dynamic-workers-give-each-ai-generated-app-its-own-database-o7onrhffh) · Cloudflare · 0 upvotes · 0 comments
- [Cloudflare Durable Objects: state that lives in one place](https://daily.dev/posts/cloudflare-durable-objects-state-that-lives-in-one-place-bshikg52i) · Flavio Copes · 0 upvotes · 0 comments

---

Tags: [#typescript](https://daily.dev/tags/typescript), [#websocket](https://daily.dev/tags/websocket)

[View this post on daily.dev](https://daily.dev/posts/create-ai-workout-plans-with-cloudflare-durable-objects-zdsytopjd)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Create AI Workout Plans with Cloudflare Durable Objects","url":"https://daily.dev/posts/create-ai-workout-plans-with-cloudflare-durable-objects-zdsytopjd","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/create-ai-workout-plans-with-cloudflare-durable-objects-zdsytopjd"},"datePublished":"2026-09-28T15:27:21.832Z","dateModified":"2026-09-28T15:27:46.583Z","description":"A developer walks through building an AI-powered workout template generator using Cloudflare Durable Objects paired with Vercel's AI SDK. The Durable Object...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/825d6a5151843b1a70d419f4a75b56bb?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/825d6a5151843b1a70d419f4a75b56bb?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Frontend Masters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Frontend Masters","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/d34dd87208f24090bfb0917307fcf89f","url":"https://daily.dev/sources/frontendmasters"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/create-ai-workout-plans-with-cloudflare-durable-objects-zdsytopjd","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"typescript,websocket","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Frontend Masters","item":"https://daily.dev/sources/frontendmasters"},{"@type":"ListItem","position":3,"name":"Create AI Workout Plans with Cloudflare Durable Objects"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/create-ai-workout-plans-with-cloudflare-durable-objects-zdsytopjd#faq","mainEntity":[{"@type":"Question","name":"How can I persist AI generation results so they survive a page refresh in a web app?","acceptedAnswer":{"@type":"Answer","text":"Use a Cloudflare Durable Object per user, running the AI prompt inside the object and saving both the prompt and result to its dedicated SQLite storage. When generation finishes, push the result to the browser over a built-in WebSocket connection; on refresh, the client reconnects to the same Durable Object and queries SQLite for prior and current session data. daily.dev surfaces patterns like this for developers designing resilient, stateful AI-driven UIs."}},{"@type":"Question","name":"How do you set up a WebSocket connection with a Cloudflare Durable Object from a web app?","acceptedAnswer":{"@type":"Answer","text":"Expose an API route (or server route) that proxies the raw request to the Durable Object's fetch method, which checks for an Upgrade header of websocket, creates a WebSocketPair, calls ctx.acceptWebSocket on the server socket, and returns the client socket with a 101 status. The Durable Object can then broadcast messages to all connected sockets via ctx.getWebSockets(). daily.dev helps developers wiring up real-time features track patterns like Durable Object WebSockets."}},{"@type":"Question","name":"Can I use Drizzle ORM with Cloudflare Durable Objects SQLite storage?","acceptedAnswer":{"@type":"Answer","text":"Yes, the drizzle-orm/durable-sqlite package provides a DrizzleSqliteDODatabase type that wraps a Durable Object's ctx.storage, letting you run type-safe SQL queries synchronously without async/await, since the underlying SQLite API inside a Durable Object is synchronous rather than promise-based. daily.dev keeps developers evaluating ORM options for edge storage informed on tools like this."}}]}
```

