Skip to content

Restrict API Keys ​

This guide creates an API key for a CI job that can do only what the job needs, expires on a schedule you choose and works only from your CI network. It then verifies the key, shows what a refusal looks like and how to recover, and rotates the key.

In this guide an API key means a developer token: the personal cbt_live_ credential you create under Settings → Developer in the web app or with the API. Enterprise API Keys are a separate credential with their own rules. For every field and rule, see Developer access.

Before you begin ​

  • To use the API steps, you need an interactive access token in $TOKEN (see Authentication). A developer token cannot create, list or revoke developer tokens. You can do every creation step in the web app instead.
  • Find the public egress addresses of your CI runners. Hosted runners often share large address pools that change; use runners or a NAT gateway with fixed public addresses. This guide uses 203.0.113.0/24 and 198.51.100.7 as example addresses.

1. Choose a permission set ​

Read the permission catalog to see which permissions a developer token can carry today:

curl https://api.chainabit.com/api/v1/auth/developer-tokens/catalog \
  -H "Authorization: Bearer $TOKEN"

For each entry in data.entries:

  • operations lists the exact routes the permission authorizes. Choose the smallest set of permissions whose operations cover every route your job calls.
  • billable is true when using the permission can spend credits.
  • dependencies lists permissions that must be granted together with it.

The job in this guide reads the wallet balance (GET /wallet/me), so it needs only wallet:read. Note catalogVersion as well: if you send it when you create the key, the request is refused if the catalog has changed in the meantime.

Always send scopes explicitly. A request without permissions creates a key with execution:run, which can spend credits.

2. Pick an expiry ​

Choose the shortest preset that fits how often you can rotate the key: 1d, 7d, 30d, 90d or 1y. For a key you rotate every quarter, use 90d.

The catalog's data.expiryOptions shows which presets you can choose now:

  • "available": false with "reason": "account_limit" means the Organization the key will be bound to limits credential lifetime. Choose a shorter preset.
  • none (no expiry) is reserved. The API currently reports it as unavailable with "reason": "non_expiring_unavailable" and refuses it.

3. Restrict the key to your CI network ​

List the egress addresses or CIDR ranges of your runners in allowedNetworks. You can send up to 100 entries, in IPv4 or IPv6. If your runners can reach the API over IPv6, list their IPv6 ranges too: an IPv4 entry never matches an IPv6 address.

Chainabit checks the public address the request arrives from. Forwarding headers set by your client are ignored, so if the job's traffic leaves through a proxy or NAT gateway, list that gateway's public address.

Create the key:

curl -X POST https://api.chainabit.com/api/v1/auth/developer-tokens \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "CI wallet check",
    "scopes": ["wallet:read"],
    "expiry": "90d",
    "allowedNetworks": ["203.0.113.0/24", "198.51.100.7"]
  }'

The response returns the key once, together with the normalized network list:

json
{
  "data": {
    "id": "00000000-0000-4000-8000-000000000001",
    "label": "CI wallet check",
    "token": "cbt_live_EXAMPLE...",
    "tokenPreview": "cbt_live_EXA...",
    "scopes": ["wallet:read"],
    "accountId": "00000000-0000-4000-8000-000000000002",
    "tokenKind": "account_bearer",
    "expiresAt": "2027-01-27T10:00:00.000Z",
    "allowedNetworks": ["203.0.113.0/24", "198.51.100.7/32"],
    "catalogVersion": "<64-character hex digest>",
    "warnings": [],
    "createdAt": "2026-10-29T10:00:00.000Z"
  }
}

Store data.token in your CI platform's secret store right away, for example as DEVELOPER_TOKEN. It cannot be shown again. Keep data.id: you need it to revoke the key.

Check two things in the response:

  • allowedNetworks holds what you meant. A single address is stored as /32 or /128, and a range is stored with its host bits cleared.
  • warnings is empty. developer_token_network_broad means one entry covers every address (0.0.0.0/0 or ::/0), so the restriction has no effect. Revoke the key and create it again with narrower ranges.

If an entry is not a valid address or range, nothing is created and the request is refused with 400 and developer_token_networks_invalid. error.details.errors names each invalid entry by its position in your list, counted from 0.

In the web app, the same settings are in the Create Token panel: Permissions, Expiration, and IP restriction with Restrict to IP addresses turned on. The panel shows how each entry will be stored before you create the key.

4. Verify with a request ​

From a CI runner, call a route the key is allowed to use:

curl https://api.chainabit.com/api/v1/wallet/me \
  -H "Authorization: Bearer $DEVELOPER_TOKEN"

A 200 response with the wallet in data confirms that the key, its permission and the network restriction work together.

To confirm that the restriction is active, send the same request from a machine outside the allowed networks, for example your laptop. It is refused with 401:

json
{
  "error": {
    "code": "developer_token_ip_denied",
    "message": "Developer token is not permitted from this network"
  }
}

The meta object is omitted here. The response never reveals which networks are allowed.

5. Recover from a refusal ​

Status and codeWhat it meansWhat to do
401 developer_token_ip_deniedThe request came from an address outside the key's allowed networks. The key is still validDo not discard the key. Check the runner's public egress address. If the list is wrong, create a replacement key with the right networks, then revoke this one
403 forbiddenThe key does not carry a permission the route needs. The message names it, for example developer_token lacks required scope: bits:readCreate a replacement key that includes the permission, then revoke this one
401 unauthorizedThe key has expired or has been revoked (Invalid or expired developer token)Create a new key. An expired key stays in your token list with the status expired
403 developer_token_lifetime_exceededThe request runs in an Organization whose maximum credential lifetime is shorter than the key's lifetimeCreate a key with a preset no longer than error.details.maxCredentialLifetimeDays

A key's permissions, expiry and allowed networks cannot be edited. Every fix above means creating a replacement and revoking the old key. See Error codes for every developer token code.

6. Rotate the key ​

There is no in-place rotation. To rotate, create a replacement, switch your systems to it, then revoke the old key. Plan the rotation before expiresAt: after that time, requests with the old key are refused with 401.

Create the replacement. Create a new key with the same permissions, expiry and networks, as in step 3. Give it a label that tells the two apart, for example CI wallet check 2027-01.

Switch your systems. Store the new key in your secret store and deploy the change to every job that used the old one.

Check that the old key is idle. List your keys and compare lastUsedAt of the old and the new key:

curl https://api.chainabit.com/api/v1/auth/developer-tokens \
  -H "Authorization: Bearer $TOKEN"

lastUsedAt is updated at most once every five minutes for repeated use from the same client, so wait a little after your last deployment.

Revoke the old key by its ID:

curl -X DELETE https://api.chainabit.com/api/v1/auth/developer-tokens/$OLD_DEVELOPER_TOKEN_ID \
  -H "Authorization: Bearer $TOKEN"

Revocation is immediate. You can also revoke the key in the web app, or run chainabit auth keys revoke with its ID.

Creating and revoking keys are recorded in the audit trail of the account the request runs in. The secret is never recorded.

Built with purpose. chainabit.com