# DigitalOcean API tokens: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/digitalocean
Last checked: 2026-10-25

DigitalOcean personal access tokens are generated in the Control Panel under Account → API → Tokens → Generate New Token. You choose a name, an expiration and scopes, and the token is shown only once. Scopes cannot be edited after creation.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Personal access token | — | Yes | Custom scopes, Read Only (`api:read`) or Full Access (`api:write`), limited by your team role | You choose the expiration when generating; after that the token stops working and is removed |

## How to create a DigitalOcean key

1. In the DigitalOcean Control Panel, go to **Account** → **API**, then the **Tokens** tab.
2. In **Personal access tokens**, click **Generate New Token**.
3. Enter a token name, choose an expiration, and select scopes.
4. Click **Generate Token** and save the token immediately; it is shown only once.

## Limiting what the key can do

Choose Custom Scopes for specific permissions (for example `database:create`), Read Only (`api:read`) for read access to all resources your team role allows, or Full Access (`api:write`). Available scopes depend on your team role, and scopes cannot be edited later, so create a new token to change them.

## How to rotate a DigitalOcean key

1. From the **…** menu next to the token on the Tokens tab, choose **Regenerate**, or generate a new token.
2. Update your applications with the new token.
3. Delete the old token if you generated a new one instead of regenerating.

## How to revoke a DigitalOcean key

1. In the Control Panel go to **Account** → **API** → **Tokens**.
2. Open the **…** menu next to the token and choose **Delete**; deleting revokes its access.

## If the key leaked

1. Delete the exposed token from the Tokens tab.
2. Generate a replacement with the narrowest scopes and a short expiry.
3. Review your account's resources for anything you did not create.

## Gotchas

- The token is displayed only once.
- Scopes cannot be edited after creation.
- Expired tokens are removed from your account and can no longer authenticate.

## Using this key with AI agents (BotPassword)

- `list_credentials`: Lists the credentials this agent is granted and what it may do with each. Never values.
- `run_with`: Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
- `http_request`: Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
- `cli_login`: Lets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
- `rotate`: Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
- `store_secret`: Saves a value the agent already holds as a new vault item.

## FAQ

### Where do I find my DigitalOcean API token?

It is shown only once when you generate it under Account → API → Tokens. If lost, regenerate it or create a new one.

### How do I revoke a DigitalOcean API token?

On the Tokens tab, open the … menu beside the token and choose Delete.

### How do I log in to doctl?

Run `doctl auth init --context <NAME>` and paste your API token when prompted.

### Can I limit what a DigitalOcean token can do?

Yes. Choose Read Only, Full Access or custom scopes when you generate it.

### Can an AI agent use my DigitalOcean key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a `.env` file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with `list_credentials`, `run_with`, `http_request`, so the agent gets the result and never the value.

## Sources

- https://docs.digitalocean.com/reference/api/create-personal-access-token/
- https://docs.digitalocean.com/reference/doctl/how-to/install/
- https://docs.digitalocean.com/reference/mcp/
