Skip to content
Rotate › Cloudflare

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.

Keysquid team · Updated · Checked against Cloudflare's docs on November 28, 2026

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}/value for 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 withWhat it isScope
cfut_User API tokenThe permissions you chose, for resources your user can reach
cfat_Account API tokenOwned by the account, not a person; survives that person leaving
cfk_Global API KeyEverything your user can do. Replace with a scoped token.
cfoat_Wrangler OAuth access tokenIssued by wrangler login
(no prefix, 40 chars)A pre-2026 API tokenStill 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

  1. Go to My Profile → API Tokens (account tokens live under the account’s own API Tokens page).
  2. Next to the token, select the three-dot menu, then Roll, then Confirm.
  3. 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

  1. Copy the token’s policies into a new one.
  2. Update CI, Terraform, Workers and DNS tooling.
  3. Verify, then delete the old token.
  4. Remember to do it again in 90 days.

With Keysquid

  1. Keysquid reads your app’s token’s permissions and creates a twin.
  2. It verifies the new token, writes it everywhere and redeploys.
  3. It deletes the old token after the grace period.
  4. 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:

  1. In Cloudflare, create a token from the “Create Custom Token” template with only User → API Tokens → Edit.
  2. 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.

Sources

  1. Cloudflare docs: Roll a token
  2. Cloudflare docs: Token formats
  3. Cloudflare docs: Create an API token
  4. Cloudflare API: Roll account token
  5. Cloudflare API: User API tokens
How to Roll a Cloudflare API Token (Step by Step)