Skip to content

Integration · Data & infra

Cloudflare Workers AI, D1 and Vectorize: the stack this site runs on

This website is a static export on Cloudflare Pages, and its assistant, contact form and analytics run as Pages Functions on the Workers runtime. We build the same way for clients who want AI at the edge with no servers to patch.

Cloudflare

Data & infra

In our build stackA tool we build with. Not a partnership, certification or reseller status.

Access

Authentication and least-privilege scopes

Bindings on the Pages project or Worker instead of keys in code, plus scoped API tokens for deploys

  • deploy token: Pages edit only
  • D1 + Vectorize edit: provisioning only
  • bindings: per environment
  • secrets: encrypted variables

Code reaches D1, Vectorize, KV and Workers AI through bindings, so the repository holds no database passwords or AI keys.

Objects

What we read and what we write

  • Pages project (static assets)

    Read: YesWrite: No

    HTML, CSS and media served from Cloudflare’s network.

  • Pages Function / Worker

    Read: YesWrite: Yes

    API routes such as chat, contact and events on the Workers runtime.

  • D1 database

    Read: YesWrite: Yes

    SQLite-compatible store for leads, sessions and the full-text index.

  • Vectorize index

    Read: YesWrite: Yes

    Embeddings for semantic search next to the D1 full-text search.

  • Workers AI binding

    Read: YesWrite: Yes

    Model and embedding calls with no API key in code.

  • KV namespace

    Read: YesWrite: Yes

    Small, fast lookups such as rate-limit counters.

Data flow

System of record and write-back

The static site and its API ship as one deployment. D1 is the system of record for leads and sessions, and Vectorize holds embeddings rebuilt from the site’s content.

  1. Static pages are served from Cloudflare’s network.
  2. API routes run as Functions on the Workers runtime, close to the visitor.
  3. Functions read and write D1, query Vectorize and call Workers AI through bindings.
  4. Anything that needs a person, such as a lead or a handoff, is stored in D1 and sent by email.
Cloudflare data flow on this website
  • Visitor browser
  • Contact form
Pages + Functions (Workers runtime)
  • D1
  • Vectorize
  • Workers AI

The steps below trace one question to this website’s own assistant, as its code handles it.

Worked example

Cloudflare in a build

This website’s assistant request path in seven steps: edge-served page, the chat Function, redaction and routing, hybrid retrieval, the model call, output checks with citations, and optional session storage.
  1. Step 01

    This page, served from the edge

    miniailabs.in is a static Next.js export on Cloudflare Pages, so the page arrived as ready-made HTML with no server render.

  2. Step 02

    The assistant posts to the chat Function

    A Pages Function checks the origin and the request size, then applies a per-visitor rate limit kept in KV.

  3. Step 03

    Redact and route

    Card numbers, IDs and keys are masked. Greetings, off-topic questions and handoff requests get a fixed reply without a model call.

  4. Step 04

    Retrieve

    An in-memory index of the site content is searched, and D1 full-text and Vectorize results join it by rank when those bindings exist.

  5. Step 05

    Answer from numbered sources

    The model is called through Workers AI or another configured provider, with the retrieved passages as its only sources.

  6. Step 06

    Check and cite

    An output check blocks banned claims, unlisted prices and unknown links, then adds citations; low confidence offers a person.

  7. Step 07

    Store the turn, if allowed

    With a database bound, the turn is kept under a hashed session id with an expiry; the visitor can delete it.

Sample workflows

What teams build with Cloudflare

  • Pattern 01

    A cited assistant on your own site

    Hybrid search over your pages in D1 and Vectorize, a model call through Workers AI and an output check before anything is shown.

  • Pattern 02

    Lead capture with an audit trail

    Form posts are validated at the edge, stored in D1 with a reference number and sent to your team by email.

  • Pattern 03

    Edge APIs for small tools

    Calculators and planners run as Functions beside the static site, with no separate server.

Failure handling

What breaks, and what the build does about it

  • A binding is missing in an environment

    Code checks each binding and degrades: retrieval falls back to the bundled index, storage is skipped, and the response still works.

  • A burst of requests from one visitor

    Per-visitor rate limits in KV return a clear error before any model call is made.

  • The model provider fails

    The next configured provider is tried; if none answers, the visitor gets a short message and upstream error details are never echoed.

Fit · Cloudflare

When it is the wrong choice

Saying no early is cheaper than rebuilding later.
  • Long-running jobs or heavy CPU work per request. Use a queue or a container.
  • A relational workload that outgrows one D1 database or needs Postgres features. Use Postgres, for example Supabase.
  • A specific large model that Workers AI does not offer. Call that provider from the Worker instead.

Alternatives worth pricing

  • Supabase

    Postgres with pgvector and row-level security for multi-tenant apps.

  • A hosted model API

    When the model you need is not on Workers AI; the Worker calls it directly.

  • A container platform

    Long-running or CPU-heavy work that does not fit the Workers runtime.

Limits

Limits and common errors

Vendor limits change; each line cites the vendor page and the date we checked it.
  • A Pages site can hold 20,000 files on the Free plan and 100,000 on paid plans, at up to 25 MiB per asset; Pages Functions requests count towards your Workers quota.

    Source: Pages limits (opens in a new tab) · Cloudflare Docs · accessed

  • Workers get 10 ms of CPU per request on Free; on Paid the default is 30 s, raisable to 5 minutes. Each isolate has 128 MB of memory.

    Source: Workers limits (opens in a new tab) · Cloudflare Docs · accessed

  • A D1 database can reach 10 GB on Workers Paid (500 MB on Free), with up to 1,000 queries per Worker invocation (50 on Free).

    Source: D1 limits (opens in a new tab) · Cloudflare Docs · accessed

  • D1 supports the FTS5 module for full-text search.

    Source: D1 SQL statements (opens in a new tab) · Cloudflare Docs · accessed

  • Vectorize allows up to 1,536 dimensions per vector and 20,000,000 vectors per index; topK is 50 when values or metadata are returned and 100 without.

    Source: Vectorize limits (opens in a new tab) · Cloudflare Docs · accessed

  • Workers AI is billed in Neurons, a measure of GPU compute, with a free daily allocation on every account.

    Source: Workers AI pricing (opens in a new tab) · Cloudflare Docs · accessed

Security

Security notes

  • Bindings replace secrets in code; the few real secrets, such as the email API key, are encrypted environment variables.
  • Every D1 query binds its parameters, so visitor input is never concatenated into SQL.
  • Chat turns are stored only under a hashed session id with an expiry, and visitors can delete them.

FAQ

Frequently asked questions

Does this website really run on Cloudflare?

Yes. It is a static export served by Cloudflare Pages, and its API routes, including the assistant and the contact form, run as Pages Functions. Any response from miniailabs.in carries Cloudflare’s headers.

Can Workers AI replace an external model API?

For many tasks, yes: classification, summaries, embeddings and grounded answers from retrieved text. When a task needs a model it does not host, the Worker calls that provider instead, behind the same interface.

Is D1 suitable for production data?

It is a managed SQLite-compatible database with a size limit per database, which suits leads, sessions, settings and search indexes. Large relational workloads belong in Postgres.

How does hybrid search work on Cloudflare?

Full-text search in D1 finds exact words, Vectorize finds passages with similar meaning, and the two ranked lists are merged so a passage that scores well on either rises. Only the top merged passages reach the model.

What does a Cloudflare build cost to run?

It depends on traffic. Static hosting is inexpensive, while Functions, D1, Vectorize and Workers AI are billed by use. The proposal estimates the running cost from your expected traffic using Cloudflare’s current pricing pages.

Next step

Have a workflow in mind? Let’s scope it together.

Book a free 30-minute strategy call. Bring one process you want to automate and we will talk through scope, integrations and a sensible first step.

Free 30-minute call · no commitment

Send an RFP or security questionnaire