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
For example, the development process of

Sometimes, you need the Agent to follow tutorials and set up some workers, KV, or R2 for you
For example,

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
User API Tokens page in Cloudflare profile, permissions include Account.API Tokens and User.API Tokens


*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
Typing API into Quick Search at the top left of Cloudflare and selecting API Tokens

Top right Create Token
API token page with Create Token button outlined in red

Get started after Create Custom Token
Token creation page with a red box marking Get started next to Create Custom Token

Set permissions Account.API Tokens
Custom token: name admin, Account.API Tokens permission set to Edit

Add a permission User.API Tokens
Adding another User.API Tokens permission to the custom token

Continue to summary at the bottom of the page
TTL set from Start Date to End Date, with Continue to summary at the bottom

Create Token
Summary page showing admin token permissions, Create Token button at the bottom

The Token will only be displayed once, save it yourself
Token created successfully, page notes the token is shown only once and can be copied

========

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
Comments