# Create and manage API tokens

> Choose what a token may do and how long it lasts, keep it safe, replace it, and know when it stops working.

An API token, which some tools call an API key, lets a script call the Clokeep API as you. The click-by-click steps to create one are in the [API introduction](/docs/api-reference/introduction#create-a-token). This page covers the choices you make and how to look after a token once you have it.

## Prerequisites

- The Admin role in the client the script works on. Only an Admin can create tokens. **API Tokens**, under **Access** in the sidebar, is also shown to an Operator or Viewer who still holds tokens there from when they were an Admin.

## Choose what the token may do

When you click **Create token**, you decide three things.

- **Token name**: name it after the script or the machine that uses it, such as `CI pipeline`. With one token per script, you can revoke one without stopping the others.
- **Abilities**: tick **Read** for a script that only reads, such as a report or a monitor. Tick **Write** for a script that runs backups, queues restores or changes records. A token without **Write** gets `403` on every call that changes something.
- **Expiration**: the token stops working after 1 hour, 5 hours, 24 hours, 1 month or 6 months, or with **Does not expire** only when you revoke it. The default is 1 month. Pick the shortest time that fits the job.

## Store the token

The token appears once, in the **API token created** dialog. Clokeep cannot show it again. If you lose it, revoke it and create a new one.

Put the token where your script reads its secrets, such as an environment variable or your CI's secret settings. Keep it out of code repositories and logs. Anyone who has the token can call the API as you, with your role, until the token expires or you revoke it.

The **API Tokens** page lists your tokens with their **Abilities**, **Last used at**, **Created at** and **Expires at**. It never shows a token's value.

<Frame caption="The API Tokens page. Last used at shows when a token last made a call.">
![The API Tokens page with one token named Deploy script, with the read ability, its last use, creation and expiry times, and a Revoke action](/images/docs/api-token-list.png)
</Frame>

## Replace a token

You can have several tokens at once, so you can replace one without a gap.

<Steps>
<Step title="Create the new token">
Create a token with the same abilities as the old one, and give it a name you can tell apart, such as `CI pipeline 2`.
</Step>
<Step title="Switch the script over">
Put the new token where the script reads it.
</Step>
<Step title="Check that the old token is idle">
On **API Tokens**, the new token's **Last used at** shows a time after the script's next run. The old token's **Last used at** stops changing.
</Step>
<Step title="Revoke the old token">
Click **Revoke** next to the old token and confirm with **Revoke token**.
</Step>
</Steps>

An expired token stays on the list until you revoke it.

## Revoke a token

Click **Revoke** next to the token and confirm with **Revoke token**. A **Token revoked** message appears. The token's next call gets `401`.

The page lists only the tokens you created in the client you are in. You cannot see or revoke another user's tokens there. An Admin revokes them on the user's page instead: see [Revoke a user's API tokens](/docs/access/users-roles#revoke-a-users-api-tokens).

## When a token stops working

A token belongs to you and to the client you created it in. Clokeep checks both on every request.

- **Another client.** A token works only in the client it was created in. For a script that works on two clients, create a token in each.
- **Your role changes.** The token keeps working within the new role. A Viewer's token can still read, but every change gets `403` with `Your role does not permit this action.` A Customer's token gets that answer on every call. As an Operator or Viewer, you can still open **API Tokens** to see and revoke your tokens, but only an Admin can create new ones. See [Users and roles](/docs/access/users-roles).
- **Your account is disabled.** Every call gets `403` with `This account is disabled.` The tokens are kept, and work again when the account is enabled again.
- **You are removed from the client.** Your tokens for that client are deleted. Their next call gets `401`.
- **The token expires or is revoked.** Every call gets `401`. An Admin of the client can revoke your tokens too.

## Next steps

<CardGroup cols="2">
<Card title="Your first API call" href="/docs/developers/first-call" icon="play">
Check the token with one request and read the answer.
</Card>
<Card title="Errors and rate limits" href="/docs/developers/errors-rate-limits" icon="book">
How a script should react to each error.
</Card>
</CardGroup>
