Documentation menu

Docs › API

API authentication

Every API request is authenticated with a bearer token. Tokens are scoped, can be limited to specific sites and IP ranges, and can expire automatically.

Creating a token

Create tokens in the dashboard under Account → API tokens, or with the CLI. A token is shown once; store it in your secret manager.

Shell
cachebz tokens create \
  --name "ci-deploy" \
  --scopes config:write,purge:write \
  --sites site_7Hq2xK \
  --expires 90d

Using a token

Send the token in the Authorization header. All requests must use HTTPS; plain HTTP requests are rejected.

curl
curl https://api.cache.bz/v1/sites \
  -H "Authorization: Bearer $CACHEBZ_TOKEN"

Scopes

ScopeAllows
sites:readList sites and read their settings.
config:writeValidate, deploy and roll back configuration.
purge:writeCreate purge requests.
analytics:readRead analytics and logs.
certs:writeUpload and delete custom certificates.
debugUse the x-cachebz-debug header on edge requests.
account:adminManage members, billing and other tokens.

Errors

Authentication errors use standard status codes and a JSON body with a stable code you can match on:

Response
HTTP/2 403
content-type: application/json

{
  "error": {
    "code": "token_scope_missing",
    "message": "This token does not have the purge:write scope.",
    "request_id": "req_01JE3XA4P9"
  }
}

Rotating tokens

  1. Create a new token with the same scopes.
  2. Deploy it to the systems that use the old one.
  3. Check the old token's last used time in the dashboard until it stops changing.
  4. Revoke the old token.
Leaked a token?

Revoke it immediately in the dashboard; revocation takes effect at every API endpoint within five seconds. Then check the audit log for actions taken with it.

Was this page helpful? Tell us what was missing at support@cache.bz. Every message is read by the team that writes these docs.