API Keys with Minimum Permissions
In the previous part, I explained how I started tracking website visits without using cookies and how I resolved the security policy block that stopped our own counter. With the traffic numbers arriving at the Cloudflare dashboard, I needed a way to feed that information directly to the Analyst, the agent responsible for preparing my daily summary.
What I wanted to solve
On October 3, 2026, my personal website went live at rodrigoesporto.com. With the visitor counter working smoothly, I did not want to log into the hosting panel every morning just to check how many people read the articles. The Analyst handles that job on my team: this agent monitors my X profile and site traffic, sending a brief summary every day.
To do this work autonomously, the Analyst needs to query Cloudflare data over the internet. There is a dangerous way and a safe way to grant that authorization to an automated assistant.
The dangerous way is handing over an account wide master key or administrator login. If I did that, the agent would have the power to alter network settings, change domain name servers (DNS), delete pages, or modify billing details. Even worse, if that credential ever leaked, anyone who grabbed it would have full control over the domain.
I wanted the safe path. I needed surgical permission: a credential created strictly for reading statistical data from that specific domain. The Analyst needed to read traffic numbers, but without any ability to modify files, touch DNS records, or change anything on the site.
I work during the day, and at night and on Sundays I build with AI agents. I went into the Cloudflare dashboard to set up this restricted access.
Because I use Cloudflare to host the pages and manage the domain, I am sharing the real choices I made for my own setup, without sponsorships or artificial neutrality.
Quick summary
- What worked: I created an API token in Cloudflare with read-only permissions for site analytics for the Analyst, and a separate token for Clef using a pre-built template.
- Cost: $0 (available on Cloudflare’s free tier).
- Time: about 30 minutes to set up the keys, resolve a copy-paste error, and verify data reading.
- The stumble: on my first attempt, I copied the entire test command from the screen (which started with “curl”) instead of copying just the token code from the top box.
- The core rule: one key per use, always with minimum permissions, and never paste credentials into chat.
First: what is an API and what is an API key
API stands for Application Programming Interface. In simple terms, it is a customer service counter built specifically for computer programs to talk to each other.
When you visit a website, you open a browser, click buttons, and read text on a screen. An automated tool or AI agent does not need buttons or a mouse. It talks to Cloudflare by sending a plain text request over the network, and the server replies with raw data, like a clean table showing how many visits occurred that day. That direct communication channel is an API.
An API key acts like an ID badge for that counter. Instead of having the agent type a human username and password every time it requests data, it presents this secret code to prove it has legitimate permission to query the system.
Think of it like a security badge at an office building. You stop at reception, receive a badge, and tap it at the turnstile to take the elevator upstairs.
The office badge analogy helps explain identification, but it has a clear limit. In the physical world, a security guard looks at your face and verifies that the badge belongs to you. In the digital world, the server only sees the code sent over the connection. Any program holding that key can pose as the agent. That is why an API key must stay secret and carry as little power as possible.
What is the principle of minimum permissions
The principle of minimum permissions, often called the principle of least privilege in security, is straightforward: give each program only the permissions strictly required to perform its task, and nothing more.
Imagine hiring someone to read your water meter once a month. You do not hand them a master key that unlocks your front gate, your front door, your bedroom, and your safe. You only give them the key to the utility box on the sidewalk. They record the number, lock the box, and leave.
The exact same logic applies to AI agents. The Analyst only needs to read aggregated visit counts. It does not need to publish new versions of pages, change mail records, or adjust domain security rules.
The main benefit here is damage control. If an administrator key with full access leaks, an attacker can erase your entire site within seconds. If a key with minimum permissions leaks, the potential damage is completely bounded by what that key can do: an attacker could at most see how many visits the site had that week, but could never take the site down or hijack the domain.
What I used
- Cloudflare API Tokens dashboard, available on the free tier.
- The Analyst: monitors my profile on X and website traffic, sending a brief daily summary.
- Clef: a team agent that received a second key generated from a pre-built Cloudflare template.
- Darth: the main team bot, which receives every request and routes it to the right agent.
I did not need any paid add-ons or third-party tools to create restricted credentials.
How it went
To configure this access safely in Cloudflare without exposing the account, I followed these steps:
- I opened my user profile settings in Cloudflare and went to the API Tokens section.
- I selected the option to create a custom token so I could define permissions manually.
- I set the exact permission for the token: read-only access for zone analytics (Zone, Analytics, Read).
- I scoped the resource: instead of granting access to every domain in my account, I restricted the token exclusively to rodrigoesporto.com.
- I completed creation and viewed the secret token displayed on the screen. The platform only displays this code once, so you have to copy it and store it immediately.
- I saved the code into the agent’s secure configuration field, avoiding any open chat windows.
- I ran a test query with the Analyst to confirm access. The test returned the visit counts on the first try, confirming the connection was secure and working.
After finishing the Analyst token, I created a second token for Clef. This time I used an existing template provided by Cloudflare that already includes the standard permissions for that role, keeping the two credentials entirely separate.
What went wrong and how I resolved it
Not everything worked on the very first click, and my mistake offers a practical lesson for anyone starting out.
When Cloudflare finishes generating a new API token, it shows a confirmation screen with two different text boxes. The top box displays only the secret token code, which is the actual credential. The bottom box shows a practical command-line example starting with “curl” so you can test the key in a terminal.
In my rush to test the Analyst, I made a basic careless mistake: I selected the entire bottom box, copied the command line starting with “curl” and everything attached to it, and pasted that whole string as if it were the API key.
When the agent tried to authenticate using an entire command line instead of the plain token code, the request failed immediately. Once I took a closer look at the screen, the issue was obvious: the test command was just an example, while the actual key sat inside the top box. I copied only the code from the top box, updated the credential, and the connection worked right away.
That experience reinforced two essential rules that I now follow across all my projects:
First rule: one key per use. Never share a single API key between two different agents or tools. When multiple programs share the same credential, you create an unnecessary dependency. If one tool is retired or compromised, you are forced to revoke access for everything else. With separate keys, you can revoke or rotate one without disrupting the rest of the team.
Second rule: never paste keys into chat. Never drop passwords, API tokens, or technical secrets into a regular chat window with an agent. Chat logs get stored in conversation history, appear on your screen, and often sync across multiple devices. Access keys belong strictly in dedicated configuration screens or protected system environment settings, where they cannot be viewed casually.
None of these tools replace judgment. They shorten the path between ‘I know what I want’ and ‘it is live.’
Costs and limits
In money, this step cost zero dollars. Cloudflare allows you to create custom API tokens at no charge on their standard tier.
In time, it took about 30 minutes to set up both keys, figure out my copy-paste mistake with the test command, and verify that data reading worked properly.
The limitations of this approach are simply the boundaries you deliberately put in place:
- The Analyst token can only read traffic metrics. If the agent tries to perform any other action, such as modifying DNS or changing security rules, Cloudflare rejects the request instantly with a permission error.
- If the domain changes or if I launch a new site in the future, this key will not work for the new address because it is strictly tied to rodrigoesporto.com.
- The token stays valid as long as I keep it active in my dashboard. I can revoke or delete it with a single click at any time if I notice unusual activity.
What I would do differently
I would look more carefully at the layout of the final confirmation screen before copying anything.
I lost a few minutes thinking the permissions were wrong when the actual issue was just pasting a sample command instead of the token code. Paying attention to what the screen actually shows saves time and prevents false troubleshooting.
Who this is for and who it is not for
This is for anyone connecting AI agents, automated scripts, or external tools to cloud services who wants to protect their site and data against accidents or leaks.
It is also for beginners who want to build sound security habits from day one, recognizing that unnecessary permissions always introduce unnecessary risk.
This is not for anyone who prioritizes convenience over safety and relies on account-wide master keys to save two minutes of setup time.
It is also not for administrative tasks that genuinely require full infrastructure control, where wider permissions are unavoidable and demand even stricter credential storage practices.
Closing
Building with AI goes beyond generating text or images; it means managing the underlying infrastructure that keeps everything running securely behind the scenes. Restricting API keys to the absolute minimum necessary gives you peace of mind, knowing each assistant performs its duties without putting the entire house at risk.
If you are connecting automated assistants to cloud services, make it a habit to restrict every access token from day one. To follow the next steps of this journey and discuss these setups, find me on X: @RodrigoesPorto.
In the next part, I will share how Arte created the animated avatars for the team, giving each agent a distinct identity with helmets inspired by Darth’s family.
Sources and links
- Official Cloudflare documentation on API tokens: https://developers.cloudflare.com/fundamentals/api/get-started/create-token/
- Internal team lessons learned log, October 3, 2026.