# Cloudflare from Beginner to Expert: Build a Full Website, Email, Storage, and AI Backend with One Domain

> This comprehensive 10,000-word guide teaches you how to master the entire Cloudflare ecosystem using just a single domain. Learn how to set up Cloudflare Pages for websites, custom domain email, R2 object storage, protect against AI crawlers, build backends with Workers and Workers AI, and even manage everything using the new Cloudflare CLI with AI agents — all within the free tier.

- Source: https://www.waytoagi.com/en/kb/learning-path/cloudflare-from-zero-to-master
- Original (Feishu, Chinese): https://waytoagi.feishu.cn/wiki/LhhHwMKioiiebqkbmQXc9S13nVd
- Updated: 2026-10-23

---

> 🔗 Original link: [https://x.com/xiaomovps/status/210837159...](https://x.com/xiaomovps/status/2108371593747709979)

> Xiaomo · X · @xiaomovps · 2026-10-09 09:38

> 📌 This article is a repost. Copyright belongs to the original author. Please refer to the original link for the authoritative version.

![](https://www.waytoagi.com/api/kb-media/RUclb7hEWopetSx9kn2cC3sdnze)

Many people first log in to Cloudflare because a website-building tutorial tells them to “connect your domain to Cloudflare.” You follow the instructions, change your nameservers, and your site loads just fine. But when you return to the dashboard, you’re faced with a long menu on the left: Domains, Compute, AI, Storage & Databases, Application Security, and Zero Trust. Everything looks useful, but you have no idea which parts matter to you.

I’ve been using Cloudflare since I started writing VPS tutorials. Over the years, I’ve written separate guides on domain hosting, CDN, WAF rules, Email Routing, and optimized IP selection. In September, I posted ten Cloudflare perks, followed by short posts on custom-domain email, blocking AI crawlers, digital business cards, building AI apps on a budget, and the new CLI. As these scattered tips piled up, I decided to bring them together in one article.

![](https://www.waytoagi.com/api/kb-media/S2OwbVNzKoPUCkxMY0UccHy8nMf)

This article follows a single domain from start to finish. First, we’ll connect the domain to Cloudflare and configure DNS and HTTPS. Then we’ll deploy a website from a GitHub repository, set up an email address on the domain that can receive messages, and use R2 to store images and backups. Finally, we’ll write a Worker that calls Workers AI to run an open-source model, and let an AI agent manage the entire account through the command line.

The title promises to take you from beginner to expert, but “expert” here has a practical scope. You’ll be able to independently set up a personal website, custom-domain email, object storage, and a small AI API on the free plan. You’ll know each service’s free-tier limits, what to check first when common errors occur, and when to pause for confirmation before handling API tokens or deleting resources. Enterprise-level WAF tuning, Zero Trust networking, and large-scale paid architectures are beyond the scope of this article.

Throughout the article, example.com stands in for your domain; simply replace it with your own as you follow along. The demo domain in the screenshots is my own, 79702701.xyz. The dashboard is in Chinese, so refer to the screenshots for the menu labels.


## Guide to This Article

**01｜Connect Your Domain First**

Chapter 1 explains what Cloudflare can do for everyday users. Chapters 2 and 3 cover connecting your domain, DNS, and HTTPS. By the end of these three chapters, your domain will be working properly on Cloudflare.

**02｜Website, Email, and Storage**

Chapter 4 deploys a website from a GitHub repository and connects a domain. Chapter 5 sets up custom-domain email, and Chapter 6 uses R2 to store images and backups. Together, these three services provide the core infrastructure most personal websites need.

**03｜Keep Unwanted Traffic Out**

Chapter 7 covers AI crawlers and bot traffic: how to find out who is crawling your site, which crawlers you can block outright, and which you can only slow down.

**04｜Add a Backend and AI to Your Website**

Chapter 8 walks you through writing your first Worker. Chapter 9 connects it to Workers AI and introduces Cloudflare’s newly released Clef decision model.

**05｜Hand It Over to an AI Agent, Then Keep a Cheat Sheet Handy**

Chapter 10 uses the new cf CLI to let AI agents such as Claude Code, Codex, or Pi manage Cloudflare. Chapter 11 summarizes free-tier limits and common issues. If you just want to solve an immediate problem, you can jump straight to the last chapter.


# 1. What Can Cloudflare Do for Everyday Users?


## 1. It Sits in Front of Your Website

Many people think of Cloudflare as a CDN that makes websites load faster. That’s only half the story.

A more accurate way to think about it is that Cloudflare sits between your visitors and your server. Once you connect your domain, visitors’ requests reach Cloudflare’s network first. Cloudflare then decides how to handle them: serve cached content directly, forward them to your server, block suspicious traffic, or pass them to code running on Cloudflare.

Its capabilities therefore fall into three layers.

- **Your website’s front door.** DNS resolution, CDN acceleration, HTTPS certificates, and basic protection. This is where most people start with Cloudflare.

- **A developer platform.** Workers runs your website and backend code, while R2, KV, and D1 handle storage. You can build a complete small application without a server.

- **AI agent infrastructure.** Workers AI lets you call open-source models directly, Clef is designed specifically to help AI agents make decisions, and the new cf CLI provides an interface built for AI agents.

## 2. The Free Plan Goes a Long Way for Personal Use

Everything in this article is done on the free plan. Personal websites, portfolios, documentation sites, and small tools will rarely hit the free-tier limits.

| Service | Free Allowance (According to Official Documentation as of October 2026) |
| --- | --- |
| Workers | 100,000 requests per day, with up to 10 milliseconds of CPU time per request; requests for static assets are free and unlimited |
| R2 | 10 GB of storage, 1 million Class A operations, and 10 million Class B operations per month; free egress |
| Workers AI | 10,000 Neurons per day |
| Email Routing | Free email receiving and forwarding |

These limits may change, so check the official documentation before putting these services into production. Details for each service are covered in its respective section.


## 3. What You Should Be Able to Do by the End

After working through this article, you should be able to do the following.

- Add a domain to Cloudflare and understand the difference between Proxied and DNS only records

- Choose the right SSL/TLS encryption mode and avoid “too many redirects” errors

- Publish a website from a GitHub repository and connect your own domain

- Receive email at an address such as hi@example.com and forward it to your regular inbox

- Create an R2 bucket and make its files publicly accessible through your own domain

- See which AI crawlers are visiting your website and enable AI Labyrinth

- Deploy a Worker that calls an open-source model and returns a response

- Have an AI agent use cf to look up commands, preview changes, and then execute them

That may look like a lot of services, but they will all come together under a single domain. Let’s start with the dashboard.


# II. Add Your Domain to Cloudflare


## 1. Get to Know the Dashboard Navigation

After you log in to the [Cloudflare dashboard](https://dash.cloudflare.com/), the left-hand menu gives you access to everything in your account. You do not need to explore every item on your first visit. Start by familiarizing yourself with the groups relevant to this article.

- **Domains**: Manage the domains you have added. Each domain has its own DNS, SSL/TLS, and security settings

- **Compute**: Home to Workers, Pages, and email services

- **AI**: Workers AI models

- **Storage & databases**: R2 object storage, Workers KV, and D1 databases

Cloudflare updates its dashboard fairly often, so menu names and locations may differ from the screenshots. If you cannot find something, press ⌘K to open the search box at the top and search for the feature by name. This is usually faster than browsing the menus.

![](https://www.waytoagi.com/api/kb-media/UdYCb7ZKloeCwgxo0pzcTTU1nAv)


## 2. Add a Domain

Go to “Domains,” choose “Onboard a domain,” and enter your root domain, such as example.com. Enter the main domain without www; you will manage subdomains through DNS records later.

On the next step, select the Free plan. Cloudflare will scan the domain’s existing DNS records and list what it finds.

The scan may not catch everything. Focus on three things: where the root domain example.com points, whether common subdomains such as www are present, and whether any email-related MX, SPF, or DKIM records are missing. Add any missing records manually before continuing. If you overlook email records here, the most common consequence is that you will stop receiving email after the switch.


## 3. Change the Nameservers at Your Registrar

Cloudflare will assign you two nameserver addresses, such as ashton.ns.cloudflare.com. Next, go back to the provider where you bought your domain—such as Namecheap, Spaceship, or Alibaba Cloud—and replace the existing nameservers with these two addresses.

Once your domain is connected, you can also find these addresses at any time under DNS → Settings for the domain.

![](https://www.waytoagi.com/api/kb-media/O3nnbVIMPo4RhJx506KcwndKnwh)

Before making the change, check one thing: if DNSSEC is enabled at your registrar, disable it first. Cloudflare’s official documentation specifically warns that switching nameservers while the old DNSSEC configuration is still active may make your domain temporarily inaccessible. Once setup is complete, you can re-enable DNSSEC on the same page.

The steps for changing nameservers vary by registrar. I previously wrote a separate guide covering the [complete steps for moving your domain’s DNS to Cloudflare](https://www.legacyvps.com/archives/add-domain-to-cloudflare). If you cannot find the relevant settings, use it as a reference.

## 4. Wait for the Changes to Take Effect and Explore the Domain Menu

Nameserver changes take time to propagate—from a few minutes to considerably longer. You do not need to do anything while you wait. Cloudflare checks automatically, and once the changes take effect, the domain’s status will change to Active.

Click the domain, and the left-hand menu will switch to its settings. AI Crawl Control, DNS, Email, SSL/TLS, and Security—all of which we will use later—are in this sidebar.

![](https://www.waytoagi.com/api/kb-media/Azutb713GoCaPDxTsuacvu2Knfh)

At this point, Cloudflare is managing DNS resolution for your domain. Next, let’s tackle the two settings most likely to cause problems: proxy status and HTTPS.


# III. DNS, Proxying, and HTTPS


## 1. Orange Clouds and Gray Clouds

Open DNS → Records for your domain. Each record has a Proxy status column.

![](https://www.waytoagi.com/api/kb-media/RRZgbtKYNoUiJvxSjpjcznV9nzd)

- **Proxied (orange cloud)**: Visitors connect to Cloudflare first, which then forwards their requests to your server. The CDN, HTTPS certificates, security protections, and caching all depend on this setting. Visitors also cannot see your server’s real IP address.

- **DNS only (gray cloud)**: Cloudflare only handles DNS resolution; visitors connect directly to your server.

You would normally enable the orange cloud for your website’s root domain and www. Use the gray cloud in the following cases:

- A hostname used to log in to your server over SSH. The proxy only forwards traffic on ports commonly used for web traffic, so SSH will not work through it.

- A hostname used by a mail server, such as mail.example.com, which an MX record points to. If you enable proxying for its A record, mail will not reach the server. Records such as MX and TXT do not have a proxy option themselves; the three MX records in the screenshot are always shown as DNS only.

- Other services that require visitors to connect directly to your server, such as certain game or database ports.

A useful habit: use a proxied hostname for your website and a separate, gray-cloud subdomain for SSH and your control panel.

Accessing proxied websites from mainland China can sometimes be slow. For tips, see my earlier [guide to selecting an optimal IP](https://www.legacyvps.com/archives/cloudflare-speed-optimization-preferred-ip-guide-single-domain).


## 2. Choosing the Wrong SSL/TLS Mode Can Make Your Site Inaccessible

Go to SSL/TLS → Overview to configure the encryption mode. This determines how Cloudflare connects to your server. With proxying enabled, connections between visitors and Cloudflare automatically use HTTPS.

![](https://www.waytoagi.com/api/kb-media/IuFRbh88goO3bPxhCXVc7f1hnAb)

- **Automatic SSL/TLS (recommended)**: Cloudflare scans your origin server and automatically applies the most secure mode it supports. For the domain in the screenshot, automatic mode has currently selected Full (strict).

- **Full (strict)**: Connects over HTTPS and validates the server’s certificate. The most secure option.

- **Full**: Connects over HTTPS but does not validate the certificate. Self-signed certificates are also accepted.

- **Flexible**: Cloudflare connects to your server over HTTP. You do not need to install a certificate on the server, but this part of the connection is unencrypted.

- **Off (not secure)**: No encryption at any point. Do not use this.

If you are unsure which to choose, leave it on automatic mode. If you want to set it manually and your server has a valid certificate, such as one from Let's Encrypt or a Cloudflare Origin CA certificate, choose Full (strict).

The most common problem with Flexible mode is a “too many redirects” error in the browser. This happens when your server redirects HTTP to HTTPS, but Cloudflare keeps connecting over HTTP, creating a redirect loop. Switching to Full or Full (strict) usually resolves it.

Websites hosted on Workers do not involve your own server, and Cloudflare handles their certificates automatically. The settings in this section mainly affect websites with an origin server.


## 3. Enable Always Use HTTPS

On the SSL/TLS → Edge Certificates page, enable Always Use HTTPS. Visitors who enter http:// will automatically be redirected to https://.

Your domain is now ready to handle visits securely. Next, let’s put some content on it.


# IV. Deploy a Website from a GitHub Repository

## 1. Deployment Now Starts with Workers

Previously, Pages was the go-to option for hosting a static website on Cloudflare. Now, the dashboard’s creation flow defaults to Workers: import a repository from GitHub, build it, and deploy it as a Worker. At the top of the page, there is still a line that says, “Need the legacy Pages workflow? Continue to Pages,” indicating that Pages is now the legacy option.

For most users, the difference is minimal. The official pricing page states that requests for static assets are free and unlimited, and the import page displays the same notice. If you later want to add API endpoints or connect storage to your website, you can do it all within the same project.

For this demo, I’m using my own Pi Bluebook repository, pi-bluebook, which is currently hosted at pi.xiaomovps.com. You can also use github-first-project, the repository created in my earlier in-depth guide, [GitHub: From Beginner to Expert](https://x.com/xiaomovps/status/2095322130422653298). A repository containing just an index.html file is enough.


## 2. Select a Repository

Go to Compute → Workers & Pages, click Create, and choose to import a repository from GitHub. The first time you do this, you’ll need to authorize Cloudflare to access your GitHub account. You can grant access only to the repository you want to deploy rather than to all your repositories.

![](https://www.waytoagi.com/api/kb-media/HsZkbdwgKopkOvxLqWLcmTRknlj)

Find and select the repository you want to deploy in the repository list, then click Next.


## 3. Build and Deployment Settings

![](https://www.waytoagi.com/api/kb-media/UHdWb4Q1UorWYtxwNxNcbA1RnAf)

- **Project name**: Defaults to the repository name and will appear in the workers.dev address.

- **Build command**: Optional. Plain HTML projects don’t need a build step. If you’re using a framework such as Hugo, Astro, or VitePress, enter the appropriate build command.

- **Deploy command**: Defaults to npx wrangler deploy. You can leave it as is.

Review the settings, then click Deploy. If deployment fails, check the first error in the build logs. In most cases, the build command or output directory is incorrect.


## 4. Get Your Website’s URL

Once deployment is complete, open the project’s overview page. Under “Domains & Routes” in the lower-right corner, you’ll find an address in the format project-name.your-subdomain.workers.dev. The “Visit” button in the upper-right corner opens the website directly. The project in the screenshot already has a custom domain connected, so pi.xiaomovps.com appears as an additional entry. A newly deployed project will only have a workers.dev address. The next section explains how to connect a custom domain.

![](https://www.waytoagi.com/api/kb-media/BiPYbfLygo4tLrx2d6Fc5oRLnIb)

From now on, Cloudflare will automatically redeploy your site whenever you push commits to main.


## 5. Connect Your Own Domain

Switch to the project’s “Domains” tab, click Add Domain under “Custom Domains & Routes,” and enter www.example.com or example.com. If the domain is already in the same Cloudflare account, the DNS records will be created automatically—there’s no need to configure them manually.

Before connecting it, make sure the hostname isn’t being used for something else. The official documentation states that a hostname with an existing CNAME record cannot be connected directly; you must delete that record first. If your root domain still points to an old website on a VPS, I recommend testing with an unused subdomain such as www or blog, then migrating once you’ve confirmed everything works.

![](https://www.waytoagi.com/api/kb-media/QYEsbN4EDoKKpDxFZeWcbJzPnie)

Once the domain is connected, visit it to access your live website. The certificate will also have been configured automatically.

If you want to build a more complete personal homepage, check out my earlier [short post on digital business cards](https://x.com/xiaomovps/status/2100768053579715028), which uses the same GitHub and Cloudflare combination.


# V. Set Up an Email Address on Your Domain to Receive Mail


## 1. Email Routing Receives and Forwards Mail

Once you have example.com, you may want an email address like hi@example.com to give your website and business cards a more professional look.

Cloudflare’s Email Routing lets you do this for free. Here’s how it works: Cloudflare receives emails sent to hi@example.com, then forwards them to your existing Gmail, Outlook, or QQ Mail inbox.

Let’s clarify its limits upfront: Email Routing handles receiving and forwarding mail; it is not a full email service. Sending emails from this address is a separate feature, called “Email Sending” in the dashboard. It is currently in Beta and is outside the scope of this article.

To use Email Routing, your domain’s DNS must be hosted on Cloudflare. We completed that step in the previous chapter.

## 2. Add a Domain

In the dashboard, go to Compute → Email Service → Email Routing. The list shows domains that are already enabled. To add a new domain, click “Add domain” in the upper-right corner.

![](https://www.waytoagi.com/api/kb-media/LjWEbquw7oW8J5xFGKkc6tqbn5b)

During setup, Cloudflare will prompt you to add several DNS records, including MX, SPF, and DKIM records. Confirm the changes; they usually take effect within a few minutes.

If this domain already uses another provider’s business email service, the existing MX records will conflict with Email Routing. Before enabling it, decide which service should receive your email. If the “DNS records” column in the list shows a configuration error, mismatched records like these are usually the cause.


## 3. Add a Destination Address First, Then Create a Routing Rule

Click the domain to see tabs such as Overview, Activity Log, Routing Rules, and Destination Addresses. If the routing status in the configuration summary on the right shows Enabled, email reception is ready.

![](https://www.waytoagi.com/api/kb-media/MPzHbQUsLoeMdXx1rRVcfhKDn1d)

First, add your regular email address under “Destination Addresses.” Cloudflare will send a verification email to that address. Click the link in the email; the address can only be used once its status changes to Verified.

Then switch to “Routing Rules” and create a rule.

![](https://www.waytoagi.com/api/kb-media/Zll8bIlGqocfuHxUGTOcjAQ3nTf)

- Email matching pattern: Enter hi before the @ sign and select your domain after it.

- Action: Select “Send to an email” and choose the email address you just verified as the destination.

- Save.

Send a test email to hi@example.com from another email account. It should arrive in your regular inbox within a few seconds to a few minutes. If it does not arrive, check your spam folder first, then make sure the only MX records remaining are Cloudflare’s.

You can create multiple rules—for example, github@, shop@, and newsletter@ for different purposes. If one address starts receiving spam, simply delete that rule. The list also includes a default “Catch-all” rule. Once enabled, it handles all addresses that do not match another rule. To take this approach further, see my earlier [Guide to Setting Up Unlimited Email Aliases](https://www.legacyvps.com/archives/cloudflare-email-routing-catch-all-guide).


# VI. Use R2 to Store Images and Backups


## 1. R2’s Biggest Advantage: No Egress Fees

R2 is Cloudflare’s object storage service. Think of it as a large warehouse for files: images, videos, backup archives, and static assets can all go there.

Its most popular feature is free outbound traffic. Many cloud storage services charge for download traffic, so bills can climb quickly when your images receive lots of views. R2’s free tier includes 10 GB of storage, 1 million Class A operations, and 10 million Class B operations per month, with no charges for download traffic itself.

Class A operations broadly cover actions such as writing and listing, while Class B operations broadly cover reads. For personal image hosting and backups, you are unlikely to exhaust these allowances.

Note that the free allowances apply only to Standard storage, not Infrequent Access storage.


## 2. Create a Bucket

Go to Storage & Databases → R2 Object Storage, then click Create bucket.

![](https://www.waytoagi.com/api/kb-media/YPA9bj279oC88TxDPoTcl5ixnvf)

- **Bucket name**: The page states that “Bucket names are permanent.” You cannot change the name after creation, so it is best to decide what the bucket will be used for beforehand.

- **Location**: Leave this set to Automatic. Cloudflare will choose a region based on your location.

- **Default storage class**: Keep “Standard” selected. Choosing “Infrequent Access” makes the bucket ineligible for the free allowances.

Click Create bucket. Once inside, drag an image into the bucket to upload it, and it will appear in the “Objects” list.

## 3. Enable Public Access Through Your Own Domain

Buckets are private by default, so their files cannot be accessed externally. To use the images on a website, you need to enable public access in the bucket’s “Settings.” There are two options.

![](https://www.waytoagi.com/api/kb-media/PeGlbDEEDoWCVjxnzJmcjz5Enhf)

- **Custom Domain.** Click Add under “Custom Domains,” enter img.example.com, confirm the DNS record, and connect it. The status usually changes to Active within a few minutes. In the screenshot, I’m using r2.79702701.xyz.

- **Public Development URL.** This is an r2.dev address. Click Enable and enter allow to confirm.

For production use, always choose a custom domain. The official documentation is clear: r2.dev addresses are rate-limited, intended only for development and testing, and do not support caching or access controls. The bucket in the screenshot has only a custom domain enabled; its Public Development URL remains disabled.

Once enabled, you can access a newly uploaded image directly at https://img.example.com/filename and use the URL on your website, in Markdown, or in your blog’s image-hosting settings.

The S3 API endpoint at the top of the settings page contains your account ID. Remember to redact it before sharing screenshots.

If you want an image-hosting service with an upload interface, take a look at CloudFlare-ImgBed, listed in the awesome-cloudflare collection. It supports R2 as a storage backend. Before deploying third-party projects like this, remember the advice from that in-depth GitHub article: check the author, maintenance status, and license first.


# 7. Keep Unwanted Traffic Out


## 1. See Who Is Crawling Your Website

Search engines are no longer the only ones crawling the web. Many AI companies now run crawlers too: some collect content to train models, while others search in real time on users’ behalf. For content websites, this traffic may consume resources without bringing in visitors.

Cloudflare manages this through AI Crawl Control in your domain’s menu, which is available even on the free plan. Its Overview page lists the crawlers that have visited your website by operator, such as OpenAI, Anthropic, Common Crawl, ByteDance, and Google, along with the number of allowed requests for each.

![](https://www.waytoagi.com/api/kb-media/PShhbvlKko8ctvx3KYDcUtANnBh)

Take my demo domain as an example. Over the past seven days, AI crawlers sent a total of 974 requests: 390 were allowed and 584 failed. OpenAI’s ChatGPT-User crawler alone accounted for 113 requests. Here, “failed” does not mean “blocked.” The page notes that 349 of those requests were for nonexistent pages and returned 404 errors. Even a small, low-traffic site sees this much activity; sites with more content will see even more.


## 2. Decide Whether to Allow or Block Crawlers Under “Security”

AI Crawl Control has several subpages: Overview, Metrics, Security, Optimization, and Signals. Allow and block settings are under “Security,” where you can configure each crawler individually.

- **Allow**: The crawler can bring citations and traffic, or you are happy for it to index your content.

- **Block**: You do not want the crawler to collect your content. When blocking, you can choose to return either 403 Forbidden or 402 Payment Required.

The rule of thumb is simple: generally allow search engine crawlers, or your site may disappear from search results. For crawlers used purely for training, decide based on how you want your content to be used.


## 3. AI Labyrinth Slows Crawlers Down Rather Than Blocking Them

Some crawlers ignore robots.txt and keep scraping under different identities. AI Labyrinth aims to lead them into a maze: it adds nofollow links that only crawlers can see, pointing to AI-generated content to distract bots that disregard crawling rules. The dashboard description makes it clear that these links do not change the page’s actual content and are visible only to bots.

To enable it, go to Security → Settings for your domain, find “AI Labyrinth,” and turn on the toggle on the right. It is currently still labeled Beta.

![](https://www.waytoagi.com/api/kb-media/ZfVKb5cVOoribkxrL8Zc88NUnOe)

It is important to distinguish this from blocking. The official documentation states that AI Labyrinth actions do not count as blocks: the requests themselves are neither blocked nor challenged. To explicitly stop a particular crawler, use the blocking controls described in the previous section. “Configure AI bot policies” on the same page lets you control AI bot access by type.

For more comprehensive protection rules, such as blocking by country, path, or request rate, see my earlier guide, [Free-Plan WAF Rules Explained](https://www.legacyvps.com/archives/cloudflare-waf).


# 8. Workers: Add Backend Logic to Your Website

## 1. What Is Workers?

The website published in Chapter 4 is static: you upload your finished pages, and everyone sees the same content. If you want a backend that can handle requests—for example, receive form submissions, call APIs, or return dynamic data—the traditional approach is to rent a server.

Workers lets you run JavaScript code on Cloudflare’s network. A request comes in, your code runs, and a response goes back. There are no servers to manage and no scaling to worry about.

The free plan supports 100,000 requests per day, with up to 10 milliseconds of CPU time per request. CPU time only counts the time your code actually spends computing; time spent waiting for network responses does not count. That means code that calls external APIs generally isn’t likely to hit this limit.


## 2. Deploy Your First Worker

To demonstrate the backend separately from the website in Chapter 4, we’ll create a new Worker here. Go to Compute → Workers & Pages, click Create, and choose Start with Hello World. Enter hello-ai as the name, then deploy it.

Once deployment is complete, you’ll get an address like hello-ai.your-subdomain.workers.dev. Open it in your browser, and you should see Hello World! returned.

![](https://www.waytoagi.com/api/kb-media/Qqnubus50oOMk1x9WiScYpDMnre)

That one line confirms that your code is running on Cloudflare’s network. In the next chapter, we’ll connect it to a model.


## 3. When You Need to Store Data: KV and D1

A Worker itself does not persist data; each request is independent. When you need to store something, Cloudflare offers two storage services with free allowances, both under the “Storage & Databases” menu.

| Storage | Best suited for | Free allowance |
| --- | --- | --- |
| Workers KV | Key-value data such as configuration, caches, and short links | 100,000 reads and 1,000 writes per day; 1 GB total storage |
| D1 SQLite database | Tabular data that needs to be queried, such as messages and order records | 5 million rows read and 100,000 rows written per day; 5 GB total storage |

The examples in this article don’t use either service. For now, just know they’re available, and connect them when your project needs them.


# IX. Workers AI: Run Open-Source Models with the Free Allowance


## 1. Call Models Without a GPU

Workers AI hosts a selection of open-source models on Cloudflare’s GPUs. Your Worker can call them directly, so you don’t need your own graphics card or a separate API key for the models.

The free plan includes 10,000 Neurons per day. Neurons are Cloudflare’s own unit of measurement, and usage varies by model and request length. To use more than the free allowance, you’ll need to upgrade to a paid plan, which charges $0.011 per 1,000 Neurons.

Under the AI menu in the dashboard, you can browse the currently supported models, including models for chat, translation, image generation, speech recognition, and more.


## 2. Bind Workers AI to Your Worker

Return to the overview page for hello-ai, find the “Bindings” card, click Add binding, and select Workers AI. Enter AI as the variable name. This binding lets your code call models through env.AI. The variable name must match the one in your code exactly, including capitalization.

## 3. Change the Code to Make It Answer Questions

Click Edit Code in the upper-right corner and replace the default code with the following.

```javascript
export default {
  async fetch(request, env) {
    const answer = await env.AI.run("@cf/google/gemma-4-26b-a4b-it", {
      messages: [
        { role: "system", content: "You are a Chinese-language assistant who gives concise answers." },
        { role: "user", content: "Explain what a CDN is in two sentences." },
      ],
      chat_template_kwargs: { enable_thinking: false },
    });
    return Response.json(answer);
  },
};
```

This calls Google's open-source Gemma 4 model, using a model ID from Cloudflare's official getting-started documentation. The messages field follows the familiar chat API format: system sets the role, and user contains the question you want to ask.

After deploying, refresh the workers.dev page you opened earlier.

![](https://www.waytoagi.com/api/kb-media/BWcLbtROxoMDWJxN9VtcC0fhnRd)

A JSON response appears in your browser, with the model's Chinese-language answer in the content field. Just like that, you have an AI endpoint up and running—with no server, no GPU, and no additional API key.

The usage field at the end of the response is also worth a look. This question-and-answer exchange used 84 tokens in total, consuming about 1.67 Neurons. Based on the free daily allowance of 10,000 Neurons, you could run roughly 5,000–6,000 short exchanges like this per day.

The model list and recommended IDs change over time. If a call fails, first check the model page in the AI menu to confirm that this ID is still available.

One more thing to keep in mind: anyone can open this workers.dev URL, and every visit consumes some of your allowance. On the free plan, calls simply fail once you exceed the daily allowance—you won't be charged. Still, after the demo, it's best to disable workers.dev access in the settings or delete the Worker altogether. If you plan to turn this into a public-facing service, add access controls first.


## 4. Clef: Models Built to Help AI Agents Make Decisions

On October 1, Cloudflare released two open-source decision-making models, Clef and Clef-flash. Unlike chat models, they don't write lengthy responses; they only answer multiple-choice questions.

You give the model some content, along with a set of questions and possible answers—for example, “Is this support ticket urgent?” or “Which team should it be routed to?” Rather than generating text, it assigns a probability to each option. Downstream programs can then use those probabilities to decide what to do next automatically.

| Model | Base Model | Key Features |
| --- | --- | --- |
| Clef | Qwen 3.8 27B | 64K context window, image input support, median latency of about 209 ms |
| Clef-flash | Qwen 3.5 9B | Median latency of about 39 ms, optimized for speed |

Both models are open-source under the Apache 2.0 license, with weights available on Hugging Face. You can also call them directly on Workers AI using @cf/cloudflare/clef and @cf/cloudflare/clef-flash.

They are well suited to steps in AI agent workflows that require quick triage or routing: Does this email need attention? Is this comment spam? Which tool should handle this task? Previously, these decisions also required a call to a large language model (LLM). Now they can be handed off to faster, purpose-built models.


# 10. Let an AI Agent Take Over: Manage Cloudflare with cf

## 1. Nearly Half of CLI Usage Already Comes from AI Agents

Cloudflare’s original command-line tool, Wrangler, is primarily used to develop and deploy Workers. According to figures shared by Cloudflare, AI agents accounted for a quarter of Wrangler usage in March 2026. By the week before cf launched, that share had risen to 48%—nearly half.

On September 28, Cloudflare released its new command-line tool, cf, which is currently in public beta. It differs from Wrangler in two main ways.

- **Broader coverage.** Wrangler has around 280 command paths, while cf covers more than 3,000 Cloudflare API operations, including DNS, R2, email, and security settings.

- **Designed for AI agents.** Results are output as JSON by default, commands can be searched using natural language, and potentially dangerous operations have extra safeguards.

Wrangler is not going away immediately. Cloudflare plans to release a final version of Wrangler with migration prompts after the public beta ends, then continue maintaining it for 18 months. Existing projects can migrate gradually. The default deployment command when importing a repository in Chapter 4 is still npx wrangler deploy.


## 2. Install and Log In

cf is installed through npm, so you need to have Node.js installed on your computer first.

```
npm install --global cf
cf auth login
```

cf auth login opens your browser. Once you authorize access on the Cloudflare page, return to the terminal to start using it.


## 3. Don’t Know the Command? Let It Search

One of cf’s most agent-friendly features is that there is no need to memorize commands in advance. Describe what you want to do in natural language, and it returns up to five matching commands.

```
cf cli search "create D1 database"
```

![](https://www.waytoagi.com/api/kb-media/FABdbXR2WoGH09xOZkacCLUYnbe)

The results are returned as JSON, with a command and description for each entry. The best match, cf d1 create, appears first. Once you find the command, you can check which parameters it requires.

```
cf schema d1 create
```


## 4. Preview Before Executing

For commands that create or modify resources, you can add --dry-run to print the request that would be sent without actually executing it.

```
cf d1 create --name my-database --dry-run
```

![](https://www.waytoagi.com/api/kb-media/Gaqxb9M6HoVO08x0iJvchpm8ndg)

The output shows the request method, endpoint URL, and request body. Once you have checked that everything is correct, remove --dry-run to execute the command. The endpoint URL also contains your account ID, so remember to redact it before sharing screenshots.

Delete operations have an additional safeguard. In non-interactive mode—that is, when an AI agent executes commands automatically—a delete command without --force outputs Aborted. and stops. To delete something, the AI agent must explicitly add this extra parameter, giving you a clear signal when reviewing the command.

Note that the command’s exit code in this case is 0, which makes it look successful even though nothing was deleted. The official documentation specifically warns that a successful exit does not mean the resource has been deleted. Have the AI agent check again after deleting to confirm the result.


## 5. Tell Your AI Agent to Use It

Add the following officially recommended instruction to your user-level AGENTS.md or CLAUDE.md so it applies across all projects:

```
When interacting with Cloudflare, use the cf CLI unless the project has a Wrangler configuration file.
```

This tells the AI agent to prefer cf when working with Cloudflare, unless the project already has a Wrangler configuration file. AI agents such as Claude Code, Codex, and Pi will then know which tool to call.

You can then ask your AI agent directly: “List the R2 buckets in my account” or “Add a CNAME record for example.com, but show me a dry run first.”


## 6. Give Tokens Only the Permissions They Need

When running an AI agent unattended, such as in a scheduled task or CI, you cannot open a browser to log in every time. Instead, create an API token and store it in the CLOUDFLARE_API_TOKEN environment variable.

Follow these three rules.

- Select only the permissions and domains required for the task. Do not select everything just for convenience.

- Set a reasonable expiration date and promptly delete tokens you no longer use.

- Do not put tokens in code, commit them to a repository, or paste them into conversations with AI. If a token is exposed, revoke it in the dashboard immediately and create a new one.

An AI agent can click buttons for you, but the permissions you give it define the potential impact if something goes wrong.


# XI. Free Tier Limits at a Glance and Frequently Asked Questions

## 1. Free Tier Allowances at a Glance

| Service | Free Allowance | When You Need More |
| --- | --- | --- |
| Workers | 100,000 requests per day, with 10 ms of CPU time per request; requests for static assets are free and unlimited | Paid plans start at $5/month, with some usage included |
| Legacy Pages | 500 builds per month, 1 concurrent build, 20,000 files per site, 25 MiB per file | See the official paid plans |
| Workers KV | 100,000 reads and 1,000 writes per day, with 1 GB of storage | Included in the Workers paid plan |
| D1 | 5 million rows read and 100,000 rows written per day, with 5 GB of storage | See the official paid plans |
| R2 | 10 GB of storage, 1 million Class A operations, and 10 million Class B operations per month, with free egress; Standard storage only | Usage-based billing for overages |
| Workers AI | 10,000 Neurons per day | $0.011 per 1,000 Neurons on the paid plan |
| Email Routing | Receive and forward email | — |

These figures come from Cloudflare’s official documentation as of October 2026 and may change in the future.


## 2. The Six Most Common Pitfalls

| Symptom | What to Check First | First Action to Take |
| --- | --- | --- |
| Your browser reports too many redirects | Whether the SSL/TLS mode is set to Flexible and the server forces HTTPS | Switch to Automatic, Full, or Full (strict) |
| Your domain still hasn’t been activated | Whether the nameservers are set correctly at your registrar and DNSSEC is disabled | Verify both NS addresses and allow time for propagation |
| You can’t receive email after setup | Whether MX, SPF, or DKIM records were missed during the scan | Add the missing email records, or check whether Email Routing’s DNS records show configuration errors |
| You can’t connect to your server over SSH | Whether the hostname you’re connecting to is proxied (orange cloud) | Use a DNS-only subdomain or connect directly via IP |
| R2 images load slowly or access is restricted | Whether you’re using an `r2.dev` URL | Switch to a custom domain |
| Your Worker reports that it has exceeded the CPU limit | Whether your code contains heavy computation or extensive loops | Move the computation elsewhere or upgrade to a paid plan |


## 3. A Practical Workflow

For your next project, consider working through these steps in order.

1. Add your domain to Cloudflare and configure DNS and HTTPS.

2. Import your website from a GitHub repository so it deploys automatically whenever you push changes.

3. If you need email, enable forwarding with Email Routing.

4. If you need file storage, use R2 with a custom domain.

5. If you need an API, write a Worker; if you also need data storage, connect KV or D1.

6. If you need a model, bind Workers AI; if you need a quick assessment, try Clef.

7. Delegate routine maintenance to an AI agent, using cf to look up commands, preview changes, and then execute them.

Not every project needs all seven steps. For most personal websites, stopping at step 3 is enough. Add the rest only when you actually need them.


## 4. Further Reading

Here are some focused tutorials I’ve written previously. Read whichever ones suit your needs.

- [A Step-by-Step Guide: How to Seamlessly Move Your Domain’s DNS Hosting to Cloudflare](https://www.legacyvps.com/archives/add-domain-to-cloudflare)

- [Cloudflare CDN Setup Tutorial](https://www.legacyvps.com/archives/cloudflare-cdn-setup-tutorial)

- [Say Goodbye to Slow Speeds! A Beginner-Friendly Guide to Selecting Optimal Cloudflare IPs](https://www.legacyvps.com/archives/cloudflare-speed-optimization-preferred-ip-guide-single-domain)

- [Cloudflare Free Plan WAF Rules: Examples and Detailed Explanations](https://www.legacyvps.com/archives/cloudflare-waf)

- [A Guide to Setting Up Unlimited Email Aliases with Cloudflare Email Routing](https://www.legacyvps.com/archives/cloudflare-email-routing-catch-all-guide)

## References

- [Adding a Domain to Cloudflare](https://developers.cloudflare.com/fundamentals/manage-domains/add-site/)

- [Pages Free Plan Limits](https://developers.cloudflare.com/pages/platform/limits/)

- [Setting Up Email Routing](https://developers.cloudflare.com/email-service/get-started/route-emails/)

- [R2 Pricing](https://developers.cloudflare.com/r2/pricing/), [R2 Public Buckets](https://developers.cloudflare.com/r2/buckets/public-buckets/)

- [Managing Crawlers with AI Crawl Control](https://developers.cloudflare.com/ai-crawl-control/features/manage-ai-crawlers/), [AI Labyrinth](https://developers.cloudflare.com/bots/additional-configurations/ai-labyrinth/)

- [Workers Pricing and Usage Allowances](https://developers.cloudflare.com/workers/platform/pricing/)

- [Workers AI Pricing](https://developers.cloudflare.com/workers-ai/platform/pricing/), [Getting Started with Workers AI](https://developers.cloudflare.com/workers-ai/get-started/workers-wrangler/)

- [Introducing Clef](https://blog.cloudflare.com/clef-decision-models/)

- [Introducing cf](https://blog.cloudflare.com/cloudflare-cf-cli-launch/), [cf and Coding Agents](https://developers.cloudflare.com/cf/agents/)
