How to roll a Cloudflare API token
Cloudflare's Roll button is one click, and it invalidates the old token straight away. That's right for a leak and wrong for a routine rotation. Here are both procedures, and how to tell Cloudflare's token types apart.
- Token formats (2026)
cfut_user API token,cfat_account API token,cfk_Global API Key, each 40 characters plus a checksum. Older tokens have no prefix and still work.- Roll in the dashboard
- My Profile → API Tokens → ⋯ next to the token → Roll → Confirm. Same permissions, new value.
- Overlap
- None when you roll: it invalidates the previous token. For zero downtime, create a second token with the same permissions instead.
- Roll by API
PUT /accounts/{account_id}/tokens/{token_id}/valuefor account tokens; the user-token equivalent lives under/user/tokens.- Shown once
- The token secret is shown only once, when it's created or rolled.
- Limits
- Optional token expiration and client IP address filtering, plus permissions scoped to accounts and zones.
- Leaks on GitHub
- Tokens found in public repos are revoked by Cloudflare, which emails you. In private repos, GitHub only notifies you.
- Avoid
- The Global API Key: full access to everything your user can do. Use scoped tokens.
- Keysquid
- Automatic: a new token with the same permissions, so old and new overlap.
Which Cloudflare credential is this?
| Starts with | What it is | Scope |
|---|---|---|
cfut_ | User API token | The permissions you chose, for resources your user can reach |
cfat_ | Account API token | Owned by the account, not a person; survives that person leaving |
cfk_ | Global API Key | Everything your user can do. Replace with a scoped token. |
cfoat_ | Wrangler OAuth access token | Issued by wrangler login |
| (no prefix, 40 chars) | A pre-2026 API token | Still valid; any roll gives it the new format |
From Cloudflare's token formats reference. The prefixes make leaked tokens easy to detect with few false positives.
If the token leaked: roll it
- Go to My Profile → API Tokens (account tokens live under the account’s own API Tokens page).
- Next to the token, select the three-dot menu, then Roll, then Confirm.
- Copy the new value. The old one is already dead, so update your apps and CI now; until you do, they get authentication errors.
Rolling keeps the token’s access and permissions, so nothing needs re-scoping.
Routine rotation: replace the token instead
For a scheduled rotation you want both tokens alive while you deploy. Cloudflare’s API lets you copy a token’s policies into a new one. With a token-management token (one that has User → API Tokens → Edit):
CF=https://api.cloudflare.com/client/v4
# 1. Read the policies of the token your app uses
curl -s "$CF/user/tokens/$OLD_TOKEN_ID" -H "Authorization: Bearer $CF_ADMIN_TOKEN" \
| jq '{policies: [.result.policies[] | {effect, resources, permission_groups: [.permission_groups[] | {id}]}]}' > policies.json
# 2. Create a new token with the same policies (and an expiry)
jq --arg name "app-$(date +%Y-%m)" --arg exp "$(date -u -d '+90 days' +%Y-%m-%dT%H:%M:%SZ)" \
'. + {name: $name, expires_on: $exp}' policies.json \
| curl -s -X POST "$CF/user/tokens" -H "Authorization: Bearer $CF_ADMIN_TOKEN" \
-H "Content-Type: application/json" --data @- | jq -r '.result.value'
# 3. Deploy the new value everywhere, check it, then delete the old token
curl -s "$CF/user/tokens/verify" -H "Authorization: Bearer $NEW_CF_TOKEN"
curl -s -X DELETE "$CF/user/tokens/$OLD_TOKEN_ID" -H "Authorization: Bearer $CF_ADMIN_TOKEN"Common places the token lives: the CLOUDFLARE_API_TOKEN secret used by Wrangler in CI, Terraform variables, DNS and certificate tooling (ACME DNS-01 challenges), and Workers or Pages secrets set with wrangler secret put.
By hand vs. with Keysquid
By hand
- Copy the token’s policies into a new one.
- Update CI, Terraform, Workers and DNS tooling.
- Verify, then delete the old token.
- Remember to do it again in 90 days.
With Keysquid
- Keysquid reads your app’s token’s permissions and creates a twin.
- It verifies the new token, writes it everywhere and redeploys.
- It deletes the old token after the grace period.
- Expiry and IP filtering are applied to every new token.
How Keysquid handles Cloudflare tokens
Automatic Keysquid creates, verifies, distributes and revokes Cloudflare keys on a schedule, with no one in the loop. API tokens, recreated with the same permissions so old and new overlap.
Setup, as the app shows it:
- In Cloudflare, create a token from the “Create Custom Token” template with only User → API Tokens → Edit.
- Copy the ID of the token your app uses. Put it in “Also revoke this existing key” when adding the key so the original is retired too.
- Writes to: API token (default variable CLOUDFLARE_API_TOKEN), in every platform and secret store you map it to.
- Interval: from every 1 hour to every 4 weeks, subject to your plan’s minimum.
- Limits Keysquid applies: An expiry date and a client IP allowlist on every token.
- Inventory: Keysquid lists every Cloudflare key the connection can see, including keys it doesn’t manage, with names and last use.
Every rotation runs in the same order: create the new key, verify it, write it everywhere, redeploy where a platform needs it, and only then revoke the previous key after a grace period. If any write fails, everything written so far is restored and the new key is revoked. The value is encrypted to the agent you run, so Keysquid’s servers never see it.
Keysquid works with user API tokens (the /user/tokens endpoints). It creates each new token from the previous one’s policies rather than rolling, which is what gives you the overlap. The only permission its own token needs is API Tokens: Edit.
Frequently asked questions
Does rolling a Cloudflare API token invalidate the old one?
Yes. Rolling generates a new value with the same permissions and invalidates the previous token, so anything still using the old value fails until you update it.
How do I rotate a Cloudflare token without downtime?
Create a second token with the same policies (via the API or by duplicating its permissions in the dashboard), deploy it everywhere, verify it, and only then delete the old token.
What does the cfut_ prefix mean?
It marks a user API token in Cloudflare's 2026 format. Account API tokens start with cfat_ and the Global API Key with cfk_. Tokens created before 2026 have no prefix and keep working.
Does Cloudflare revoke leaked API tokens automatically?
For public GitHub repositories, yes: GitHub reports the token, Cloudflare revokes it and emails you. For private repositories GitHub only notifies you, and you have to rotate the token yourself.
Should I use the Global API Key?
No. It has full access to everything your user can do and can't be scoped. Create API tokens with only the permissions each tool needs.