How to Set Up Cloudflare API Token for Your Agent
Preface
Sometimes, when developing for an Agent, you need the Agent to help you test worker projects
Sometimes, you need the Agent to follow tutorials and set up some workers, KV, or R2 for you
All the above operations require a prerequisite: you need to set up Cloudflare's API token for the Agent to use.
Cloudflare's API token can be set with the following permissions: Account.API Tokens, User.API Tokens
A token with these permissions can create smaller tokens with specific permissions
*The following practical methods are all completed under the conditions of Hermes connecting to tencent/hy3:free
Practice 1
If your Agent runs on your own computer.
You can open the Chrome browser, log in to your Cloudflare account, and then tell your Agent,
The current browser page is already logged into the Cloudflare account, please continue to operate and complete creating an API token with Account.API Tokens and User.API Tokens permissions
Then you can save this token separately. You can also tell the Agent to save it in its own .env.
Practice 2
If your Agent runs on a 2G RAM VPS.
You can tell your Agent,
Launch the browser, let me connect via VNC to log into the Cloudflare account
After you complete the login, tell your Agent,
The browser is now logged into the Cloudflare account, take over and continue operating to complete creating an API token with Account.API Tokens and User.API Tokens permissions
Then you can save this token separately. You can also tell the Agent to save it in its own .env.
Practice 3
If your Agent runs on a 1G RAM VPS.
In this case, it will be somewhat difficult for the Agent to open a browser.
You can let the Agent act as a "coach" to guide you through specific operations.
I want to create an API token with Account.API Tokens and User.API Tokens permissions in Cloudflare
Please guide me step by step on how to operate
During this process, if you encounter any problems, take a screenshot and ask the Agent, "Where should I click?"
Practice 4
Traditional manual method
Log in to your Cloudflare account
Top left Quick Search, type API, select API Tokens
Top right Create Token
Get started after Create Custom Token
Add a permission User.API Tokens
Continue to summary at the bottom of the page
Create Token
The Token will only be displayed once, save it yourself
========
Postscript
Note that the operational permissions of this API token are equivalent to logging in with your username and password. So I suggest you not use a relay station.
To be more conservative, don't use your main Cloudflare account.
If your Agent tells you with the Token of the above permissions, "Oh, this Token doesn't have the permission to create workers", you tell your Agent
The permissions of this token are Account.API Tokens, User.API Tokens, it can create smaller tokens with specific permissions, go study the Cloudflare API documentation yourself
========