How to Build and Deploy an AI-Powered Website Using Cloudflare
A complete, practical walkthrough: plan and build a fast static site with Astro, add AI features sensibly, and deploy it on Cloudflare Pages with a custom domain, SSL, and security headers.
Affiliate disclosure: This article contains links to products and services. If you buy through them, we may earn a commission at no extra cost to you. This never changes which products we cover or how we assess them. See our Affiliate Disclosure.
Table of contents
- Key takeaways
- Step 0: Plan before you build
- Decide what the site is
- Decide what “AI-powered” means on your site
- Choose the stack
- Step 1: Set up your environment
- Step 2: Scaffold the Astro site
- Step 3: Add your AI feature (bounded, cached, key-safe)
- Step 4: Put the project on GitHub
- Step 5: Deploy to Cloudflare Pages
- Know your limits (verified 30 November 2026)
- Step 6: Connect your custom domain and SSL
- Step 7: Add security headers
- Step 8: Pre-launch checklist
- Maintenance: the routine that keeps it alive
- Limitations of this approach
- FAQ
- Is Cloudflare Pages really free for a website like this?
- Do I need the Cloudflare adapter for Astro?
- Where do I put my AI API key?
- Can I use a domain I registered somewhere else?
- What happens if I exceed a free limit?
- How do I update the site after launch?
- Conclusion
- Sources
There is a pattern behind most fast, inexpensive websites launched in 2026: build the site as static files, generate anything intelligent at build time or through a small serverless function, and serve the result from a global edge network. Cloudflare Pages is one of the cleanest ways to run that pattern. Static assets are served free and unmetered, Git pushes deploy automatically, SSL is handled for you, and the free tier is generous enough for a serious content site. Pair it with a content-focused framework such as Astro, and you have a stack that can carry a blog, a publication, a portfolio, or a small business site without a server to patch at 2 a.m.
This guide walks the whole path: planning what “AI-powered” should actually mean for your site, building with Astro, version-controlling with GitHub, deploying to Cloudflare Pages, connecting a custom domain with SSL, adding security headers, and maintaining the site afterwards. Every step is written so you can follow it in order. Limits and version facts were verified on 30 November 2026 against Cloudflare’s official documentation and the sources listed at the end — check those pages before relying on any number, because platform limits change.
Key takeaways
- Build static first. Pre-rendered pages are fast, cheap, and reliable. Add dynamic behaviour only where it earns its keep.
- “AI-powered” should mean specific features — AI-assisted content production, on-site search or chat via an API, personalisation, or generated media — not a vague label. Each feature has a cost and a failure mode; plan for both.
- Cloudflare Pages free tier (verified November 2026): 500 builds/month, 1 concurrent build, 20,000 files per site, 25 MiB per file, 100 custom domains per project, with static asset requests free and unlimited. Pages Functions count against Workers limits (100,000 requests/day on the free Workers plan; Workers Paid starts at $5/month).
- Astro is the natural fit for content sites: it ships zero JavaScript by default, supports Markdown content collections, and its current major version is Astro 7 (released 22 June 2026), with Astro 7.4 the latest minor line as of October 2026.
- Security is mostly configuration: HTTPS enforced by Cloudflare, a
_headersfile for security headers, secrets kept in environment variables (never in the repository), and least-privilege API tokens for anything your functions call.
Step 0: Plan before you build
Decide what the site is
Write down, in one sentence each: the audience, the main content type (articles, documentation, products, portfolio), and the action a visitor should take (subscribe, enquire, buy, book). Every later decision — framework features, AI features, analytics — should trace back to those sentences. Sites fail by accumulating features, not by lacking them.
Decide what “AI-powered” means on your site
Pick from concrete options, and be honest about which you will actually maintain:
| AI feature | How it typically works | Cost / risk to plan for |
|---|---|---|
| AI-assisted content | You draft and edit articles, summaries, and metadata with AI tools before publishing; the site itself stays static | Editorial time for fact-checking; no runtime cost |
| AI search or Q&A chat | A Pages Function calls an AI provider’s API with your site’s content as context | Per-request API cost; rate limiting needed; answers can be wrong — label them |
| AI-generated media | Images generated during production, stored as normal site assets | Generation cost at production time; licensing checks |
| Personalisation | A Function adapts content by country, language, or referral source | Complexity; privacy obligations; test carefully |
| Server-side AI features | On-demand generation (summariser, translator) via Functions + provider API | Highest cost and abuse risk; needs caching and quotas |
For a first launch, the strongest default is: static site + AI-assisted content + optionally one bounded AI feature (search/Q&A is the usual candidate). Everything else can be added once real visitors tell you what they need.
Choose the stack
- Framework: Astro for content-driven sites. (If your site is primarily an interactive app, a different framework may fit better — but then much of this guide’s static-first advice matters even more.)
- Styling: Tailwind CSS via Astro’s integration, or plain CSS. Keep it simple; design systems can grow later.
- Content: Markdown/MDX files in the repository, managed through Astro content collections with a typed schema.
- Hosting: Cloudflare Pages, connected to a GitHub repository.
- Domain: registered wherever you prefer, with DNS on Cloudflare (required for the smoothest Pages custom-domain flow).

Laptop on a cloud layer with a website window rising at sunrise. Editorial illustration.
Step 1: Set up your environment
You need four things installed or created:
- Node.js 22 or later (Astro 7 requires a modern Node; check the current Astro docs for the exact minimum before installing).
- Git and a GitHub account.
- A Cloudflare account (free).
- A code editor — VS Code is the common default.
Verify your setup:
node --version
npm --version
git --version
Step 2: Scaffold the Astro site
Create the project and run it locally:
npm create astro@latest my-ai-site
cd my-ai-site
npm install
npm run dev
Open the local address the terminal prints (typically http://localhost:4321). You should see the starter site. Now give the project a production shape:
my-ai-site/
public/
_headers # security headers (Step 7)
images/ # static images, including article art
favicon.svg
src/
content/
articles/ # your Markdown articles
layouts/
BaseLayout.astro
pages/
index.astro
articles/[...slug].astro
config.ts # central site settings: name, URL, socials
astro.config.mjs
package.json
Two habits pay for themselves immediately. First, put every site-wide value — site name, production URL, social handles, contact email — in one central config file, never scattered through templates. Rebranding or changing a domain later becomes a one-file edit. Second, define your article schema up front with Astro content collections, so a missing description or a malformed date fails the build instead of breaking a page quietly in production:
// src/content.config.ts
import { defineCollection, z } from "astro:content";
const articles = defineCollection({
type: "content",
schema: z.object({
title: z.string(),
description: z.string(),
pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
category: z.string(),
tags: z.array(z.string()),
draft: z.boolean().default(false),
}),
});
export const collections = { articles };
Keep draft: true on unfinished pieces and filter drafts out of listings and feeds in production builds.
Step 3: Add your AI feature (bounded, cached, key-safe)
If you are adding a runtime AI feature — the Q&A/search pattern is shown here — the architecture is always the same three parts:
- A Pages Function (server-side code in a
functions/directory, or an Astro server endpoint with the Cloudflare adapter) receives the visitor’s question. - The Function calls your AI provider’s API using a key stored as a Cloudflare environment variable — never in code, never in the repository.
- The Function returns the answer, ideally after checking a cache so repeated questions do not repeat the API bill.
// functions/api/ask.ts — illustrative Pages Function shape
export const onRequestPost: PagesFunction<Env> = async ({ request, env }) => {
const { question } = await request.json();
if (!question || question.length > 500) {
return new Response("Invalid question", { status: 400 });
}
// Call your AI provider here using env.AI_API_KEY.
// Add: input limits, rate limiting, response caching, and error handling
// before this handles real traffic.
return Response.json({ answer: "…" });
};
Non-negotiable guardrails for any public AI endpoint: cap input length, rate-limit by IP (Cloudflare offers rate-limiting rules and Turnstile for abuse control), cache aggressively, set a spending alert with your AI provider, and label AI answers as AI-generated with a note that they can be wrong. An unprotected AI endpoint is an invitation for someone else to spend your API budget.
Static alternative worth considering: if your “AI feature” is really just content production — articles, summaries, translations, image generation — do it at build time or in your editorial process and ship the results as static files. You get the same visitor experience with no runtime cost, no keys to protect, and nothing to abuse.
Step 4: Put the project on GitHub
git init
git add .
git commit -m "Initial site"
git branch -M main
git remote add origin https://github.com/YOUR-USERNAME/my-ai-site.git
git push -u origin main
Before pushing, confirm your .gitignore excludes node_modules/, dist/, and any .env files, and search the repository once for anything that looks like an API key. Secrets committed to Git history are compromised even if deleted later — rotate them, do not just remove the line.
Step 5: Deploy to Cloudflare Pages
- In the Cloudflare dashboard, go to Workers & Pages → Create → Pages → Connect to Git.
- Authorise GitHub and select your repository.
- Configure the build:
- Framework preset: Astro
- Build command:
npm run build - Build output directory:
dist - Root directory: leave default unless your site lives in a subfolder.
- Add any environment variables your build or Functions need (Step 3’s API key goes here, marked as a secret/encrypted variable).
- Click Save and Deploy. The first build typically completes in a minute or two for a small site.
- Visit the assigned
*.pages.devURL and click through every page type: home, article, listing, 404. Check images load and that no draft content is visible.
From now on, every push to main triggers a production deployment automatically, and pushes to other branches create preview deployments with their own URLs — use previews to review changes exactly as visitors will see them. Rollback is built in: the Pages dashboard keeps previous deployments, and redeploying an earlier one is a couple of clicks (deployments are retained for 30 days, with the 100 most recent plus the current production deployment kept — per Cloudflare’s limits documentation, verified November 2026).
Know your limits (verified 30 November 2026)
| Limit (Free plan) | Value | Source |
|---|---|---|
| Builds per month | 500 | Cloudflare Pages limits docs |
| Concurrent builds | 1 | Cloudflare Pages limits docs |
| Build timeout | 20 minutes | Cloudflare Pages limits docs |
| Files per site | 20,000 | Cloudflare Pages limits docs |
| Max single file size | 25 MiB | Cloudflare Pages limits docs |
| Custom domains per project | 100 | Cloudflare Pages limits docs |
| Projects per account | 100 | Cloudflare Pages limits docs |
| Static asset requests | Free and unlimited | Cloudflare Pages/Functions pricing docs |
| Pages Functions requests | 100,000/day on Workers Free; Workers Paid from $5/month includes 10M requests/month | Cloudflare Workers pricing docs |
The practical reading: a content site will not trouble the free tier. The limits that bite first in real life are the 25 MiB per-file cap (move video and large downloads to Cloudflare R2 or a media host) and Functions quotas if a dynamic feature gets popular.
Step 6: Connect your custom domain and SSL
- In your Pages project, open Custom domains → Set up a custom domain and enter your apex domain (e.g.,
example.com). - If the domain’s DNS is already on Cloudflare, the required DNS record is created for you. If not, either transfer DNS to Cloudflare (recommended — add the domain to Cloudflare and update nameservers at your registrar) or create the CNAME record Pages shows you.
- Add the
wwwsubdomain as a second custom domain and set up a redirect fromwwwto the apex (or the reverse — pick one canonical host and be consistent everywhere, including your site config and sitemap). - Wait for the domain status to show Active. Cloudflare issues and renews the TLS certificate automatically — there is nothing to install and no renewal date to calendar.
- Enforce HTTPS: in the Cloudflare dashboard under SSL/TLS, set the encryption mode to Full (Strict) and enable Always Use HTTPS. Pages sites are served over HTTPS by default; these settings make sure origin and redirect behaviour match that expectation across the whole zone.
Test the result: load the site on https://, confirm the padlock with no mixed-content warnings, and confirm http:// and www both redirect to your one canonical address.
Step 7: Add security headers
Create a _headers file in public/ (Pages copies it to the output and applies the rules; the file supports up to 100 rules):
/*
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
Strict-Transport-Security: max-age=31536000; includeSubDomains
Add a Content-Security-Policy only when you can test it properly — a guessed CSP breaks sites (blocked fonts, scripts, and embeds) more often than it protects them. Start with the headers above, then introduce a CSP in report-only mode, review what it reports, and enforce it once it is clean. Astro 6 and later also offer framework-level CSP support worth reviewing in the Astro docs. Also add a _redirects file for moved pages as your site evolves (Pages supports up to 2,000 static and 100 dynamic redirect rules), rather than leaving old URLs to 404.
Beyond headers: enable Cloudflare’s free bot and DDoS protections (on by default for proxied traffic), turn on DNSSEC for your domain in the Cloudflare DNS settings, and protect the Cloudflare account itself with two-factor authentication and a least-privilege API token for any automation.
Step 8: Pre-launch checklist
- Every page type checked on the production URL — on a phone, not just a desktop browser
- Images display by default on mobile, are compressed, and have meaningful
alttext - Titles, descriptions, canonical URLs, sitemap, and
robots.txtpresent and correct -
ads.txtpublished if you plan advertising; analytics installed if you want it - Privacy, terms, about, and contact pages live and linked in the footer
- AI features labelled; AI endpoint rate-limited, cached, and spending-capped
- No secrets in the repository; environment variables set in the Pages dashboard
- 404 page exists and is helpful
- Backups understood: your Git repository is the backup — keep it that way by never editing only in a dashboard
Maintenance: the routine that keeps it alive
- Weekly: review Cloudflare analytics and any AI-feature usage/cost; check for failed builds.
- Monthly: run
npm outdated, apply framework and dependency updates on a branch, review the preview deployment, then merge. Astro moves quickly — Astro 7 followed Astro 6 within months — so schedule upgrades rather than discovering them. - Quarterly: re-check Pages limits and pricing against Cloudflare’s current docs; audit environment variables and API tokens; review security headers with an online header checker; prune draft and stale content.
- Continuously: treat content quality as maintenance. AI-assisted publishing makes volume easy; accuracy, sourcing, and updating old articles are what keep a publication trustworthy and ranking.
Pros of this stack: near-zero hosting cost at content-site scale; global edge performance without server administration; Git-based deploys with previews and instant rollback; SSL and DNS under one roof. Cons: static-first means genuinely dynamic features need Functions and their quotas; the 25 MiB file cap excludes media hosting; you are responsible for your AI provider’s costs and abuse controls; deep Next.js-style server features are not Pages’ home ground — choose the framework to fit the platform, not the reverse.
Limitations of this approach
- Not an app platform. Accounts, payments, and heavy personalisation push you toward Workers, databases (D1), storage (R2), and queues — all available on Cloudflare, but beyond a Pages tutorial’s scope and free-tier comfort.
- Build-time content has a ceiling. Tens of thousands of pages or minute-by-minute content changes strain a build-and-deploy model; that is when hybrid rendering or a CMS earns its complexity.
- AI features are only as good as their guardrails. Cost, accuracy, and abuse problems do not appear at ten visitors a day; they appear on the day something you publish gets shared widely. Build the limits in Step 3 before you need them.
- Vendor dependence is real. Pricing, limits, and framework direction change — the Astro project itself joined Cloudflare in January 2026, a reminder that even your framework’s home can move. The mitigation is the boring one: standard tools, content in plain Markdown, and a repository you fully own.
FAQ
Is Cloudflare Pages really free for a website like this?
For a static content site, effectively yes: static asset requests are free and unlimited, and the free plan includes 500 builds a month — far more than a publication typically uses. Costs appear when you add Functions at scale (Workers Paid starts at $5/month), register domains, or pay an AI provider for runtime features. Verified against Cloudflare’s documentation on 30 November 2026.
Do I need the Cloudflare adapter for Astro?
Not for a fully static site — plain astro build output deploys to Pages with no adapter. You need @astrojs/cloudflare when you use Astro’s server-rendered routes or Astro-specific server features on Cloudflare. Add it when a feature requires it, not by default.
Where do I put my AI API key?
In the Pages project’s environment variables in the Cloudflare dashboard (encrypted), referenced from your Function’s environment — never in source code, never in the GitHub repository, and never in client-side JavaScript, where anyone can read it. If a key is ever committed or exposed, rotate it immediately.
Can I use a domain I registered somewhere else?
Yes. The smoothest route is to add the domain to Cloudflare and point its nameservers at Cloudflare at your registrar; Pages then configures DNS and certificates automatically. Keeping DNS elsewhere and adding manual CNAME records also works for subdomains, but the apex domain is much easier with Cloudflare DNS.
What happens if I exceed a free limit?
Builds pause when the monthly build quota is exhausted, and Functions stop serving when the Workers daily quota is hit, until the window resets or you upgrade. Static pages keep serving — which is the strongest practical argument for the static-first design this guide recommends.
How do I update the site after launch?
Edit content or code locally (or directly in GitHub), commit, and push. Pages builds and deploys automatically; branch pushes give you preview URLs for review. There is no server to log into and nothing to upload by hand.
Conclusion
A professional AI-powered website does not require a server, a DevOps habit, or a hosting bill that grows with your traffic. It requires clear planning about what the AI parts are actually for, a static-first build in a framework like Astro, disciplined handling of secrets and costs for any runtime AI feature, and a deployment pipeline — GitHub into Cloudflare Pages — that makes publishing and rolling back equally easy. Follow the steps in order, respect the limits in the table, keep your content in plain Markdown under your own control, and the result is a site that is fast everywhere, cheap to run, and simple to maintain long after launch day.
Sources
Platform limits, pricing structure, and framework versions in this article were checked on 30 November 2026 against the following sources. Confirm current figures on Cloudflare’s and Astro’s official pages before making purchasing or architecture decisions.
- Cloudflare Pages — Limits (official documentation, updated 2026-11-28): https://developers.cloudflare.com/pages/platform/limits/
- Cloudflare Pages Pricing and Free Tier Limits (2026): https://gautamkhorana.com/blog/cloudflare-pages-pricing-free-tier-2026/
- Astro 7 release coverage — Coder Legion: https://coderlegion.com/23165/astro-7-whats-new-whats-faster-and-what-breaks
- Astro — official blog (Astro 7.4, October 2026): https://astro.build/blog/
Sources & further reading
Written by
Editorial Team
The NovaPulse editorial team researches, writes and fact-checks every article against primary sources before publication.
Spotted an error? Email corrections@novapulse.example.com — see our Corrections Policy.