How TalkToMySites runs on Cloudflare
One Worker, a handful of bindings and no outside AI provider. A tour of the Cloudflare products behind TalkToMySites and what each one does.

TalkToMySites is a single Cloudflare Worker. The dashboard, widget API, MCP server, crawler and file server ship as one deploy, and all state sits behind bindings in wrangler.jsonc. There's no outside AI provider and no server to patch.
Here's what each Cloudflare product does. For retrieval details (chunking, reranking, prompts), see How TalkToMySites answers from your pages.
The bindings
Product | Binding | Used for |
|---|---|---|
Workers |
| Everything: routing, API, indexing, file serving |
Workers Static Assets |
| The Astro build and |
Workers AI |
| Embeddings, reranking, answers, PDF conversion |
Vectorize |
| One index, one namespace per site |
D1 |
| Users, organizations, billing, sites, pages, chat history |
R2 |
| PDFs that site owners upload |
Queues |
| One message per page to crawl and embed |
Cron Triggers |
| Indexing dispatch, refreshes, webhook retries, retention and weekly reports |
Rate Limiting | eight limiters | Chat, sessions, sign-in, events, leads, MCP searches |
Email Service |
| Verification, email change, team invites, lead alerts, weekly reports, webhook alerts |
Turnstile is the one product that isn't a binding. Site owners can turn it on per site.
One Worker, three handlers
src/worker.ts exports fetch, scheduled and queue.
fetch routes by path. The widget's paths (/api/session, /api/chat, /api/event, /api/lead, /api/health, /widget.js, plus its translations and custom CSS) and the API-key /api/v1 go to a small Hono app that never touches Astro or auth. /mcp/<site id> goes to the MCP server. Uploaded files go to the file server, on its own files.talktomysites.com domain. Everything else goes to Astro, which renders the dashboard on app.talktomysites.com.
From question to streamed answer
The widget is a plain script that renders into a Shadow DOM, so the host page's CSS can't break it.
1. Session. When the panel opens, the widget asks /api/session for a token. It's an HMAC over the site ID, the page's hostname, the visitor's network and an expiry 30 minutes out. If the site has Turnstile on, the first call returns the site key, the widget runs the challenge, and only a passed challenge gets a token.
2. Checks. /api/chat checks the Origin header against the site's domain, verifies the session and that the site's domain has been verified, then calls two rate limiters: one keyed on site plus client IP (20 a minute), one on the site alone (300 a minute). Then it checks the organization's monthly question quota in D1. These run before any AI call, so a rejected request never reaches Workers AI.
3. Retrieval. The question is embedded with @cf/baai/bge-small-en-v1.5 (384 dimensions). Vectorize returns the 20 nearest chunks from that site's namespace, and @cf/baai/bge-reranker-base re-scores them against the question. The top 4 go to the model, with at most 2 from any one page.
4. Generation. The answer comes from @cf/google/gemma-4-26b-a4b-it on Workers AI, at temperature 0.2. If retrieval found nothing, the model isn't called at all and the widget gets a fixed "couldn't find anything" reply. After an answer, one more short call to the same model (temperature 0, 8-second timeout) can label whether the visitor asked for a person and whether the reply says the pages don't cover the question. It only runs when the English patterns can't judge, or when the site uses a role or its own instructions.
5. Streaming. The Worker re-emits Workers AI's stream as its own server-sent events: meta first (the answer ID and the sources), then token events, then done or error. The finished answer is written to D1 in waitUntil, after the response has gone out.
Crawling and indexing
Adding a site writes one pending row per URL from the sitemap, feed, llms.txt or pasted list (after path filters) into a pages table in D1. D1 is the source of truth; the queue only carries page IDs.
Dispatch. Every minute the cron claims pending pages round-robin across sites, so a big site can't starve a new one, and tops the queue up to 60 pages in flight. A claim is a timestamp on the row. If a message is lost, the claim expires after 15 minutes and the page goes out again.
Consume. The consumer takes batches of up to 10 messages, waits at most 5 seconds to fill one, and runs at most 3 at once. That keeps indexing inside Workers AI rate limits. Each message is one page: fetch it (with If-None-Match when we have an ETag), pull the text out with the native HTMLRewriter, chunk it, embed it and upsert into Vectorize.
Skip what didn't change. Each page gets a SHA-256 of its title, description and text. If the hash matches what's stored, the old vectors stay and nothing is embedded.
Failures. A Workers AI rate limit releases the rest of the batch to the next tick without spending queue retries. Other errors retry after 30 seconds, and a page is marked failed after 5 attempts.
The same cron runs scheduled refreshes (weekly on Starter, daily on Pro), which queue only new or changed pages. Deploy hooks and the API start the same re-crawl on demand. See Keeping answers current.
Uploads in R2
Uploaded PDFs live in R2 under <siteId>/<pageId>.pdf. Each one also gets a pages row whose URL is on the files host: /files/<24-character random id>/<name>.pdf. The random ID is the only key.
The indexer reads uploads straight from R2, then treats them like a crawled PDF. Both go through Workers AI's toMarkdown, so PDF parsing runs on Cloudflare's side, not in the Worker's CPU budget.
Serving passes conditional and Range headers through to R2, so browsers get 304s and partial content. Responses can't be framed and cache for only 5 minutes, so a deleted file disappears soon. The files host serves nothing else and carries no app cookies.
The marketing site
talktomysites.com, including this blog and the docs, is a separate Worker. It's built on EmDash, a CMS on Astro, using the Cloudflare adapter: content in D1, media in R2, and form notifications sent through Cloudflare Email Service.


