Cloudflare API

Set up API access for Cloudflare, enabling management of DNS, CDN, Workers, and security settings programmatically.

⏱ 5 minutes cdn edge dns dash.cloudflare.com
getapi cloudflare

Prerequisites

  • A Cloudflare account

Credentials

Variable Description Sensitive
CLOUDFLARE_API_TOKEN Scoped API token for Cloudflare API access Secret

Setup Steps

  1. 1 Info

    We'll create a scoped Cloudflare API token. Cloudflare recommends API tokens over the legacy Global API Key because tokens can be scoped to specific permissions and zones.

  2. 2 Open URL

    Opening the Cloudflare API tokens page. Sign in if prompted.

    https://dash.cloudflare.com/profile/api-tokens
  3. 3 Info

    Click 'Create Token'. You can use a template (e.g. 'Edit zone DNS', 'Read All Resources') or click 'Create Custom Token' for fine-grained control. Select the permissions and zones your app needs.

  4. 4 Confirm

    Token created? (You should see a summary page with the token value.)

    Checkpoint — confirm before continuing
  5. 5 Input

    Copy the API token and paste it here:

    → CLOUDFLARE_API_TOKEN
    40 characters
  6. 6 Validate

    Checking your API token works...

    API token verified. You're all set.
    Couldn't verify the API token. Make sure you copied it correctly and it hasn't been revoked.

Things to Know

  • API tokens are only shown once when created. If you lose it, you'll need to create a new one.
  • Always use scoped API tokens instead of the Global API Key. Tokens can be limited to specific zones and permissions.
  • Cloudflare's free plan includes CDN, DNS, DDoS protection, and basic WAF rules.
  • The API has a rate limit of 1,200 requests per 5 minutes. Batch operations where possible.
  • Token permissions are additive — start with minimal permissions and add more as needed.