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

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

Heroku Platform API requests authenticate with a bearer token. `heroku auth:token` prints a short-lived token (valid up to one year by default), while `heroku authorizations:create` makes a non-expiring `HRKU-` token with global scope. Set the token in `HEROKU_API_KEY` for scripts and CI.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Authorization token (non-expiring) | `HRKU-` | Yes | global (as created by `heroku authorizations:create`) | Does not expire |
| CLI token | — | Yes | Your account | Valid for a maximum of one year by default |

## How to create a Heroku key

1. Install the Heroku CLI and sign in with `heroku login`.
2. Run `heroku authorizations:create -d "description"` to create a non-expiring token, or `heroku auth:token` to print a short-lived one.
3. Copy the token and set it as `HEROKU_API_KEY` where it is needed.

## Limiting what the key can do

Tokens made with `heroku authorizations:create` have `global` scope in Heroku's quickstart example. Federated SSO users cannot create them; Heroku recommends a separate user, invited to the organization without being added to the identity provider, to generate and manage the organization's tokens.

## How to rotate a Heroku key

1. Create a new authorization with `heroku authorizations:create`.
2. Update `HEROKU_API_KEY` in your scripts and CI.
3. Remove the old authorization.

## How to revoke a Heroku key

1. List authorizations with `heroku authorizations`.
2. Revoke one with `heroku authorizations:revoke <id>`.

## If the key leaked

1. Revoke the exposed authorization.
2. Create a replacement and update `HEROKU_API_KEY` wherever it is used.
3. Review recent app activity for changes you did not make.

## Environment variables

- `HEROKU_API_KEY`

## Gotchas

- `heroku auth:token` tokens expire (up to one year by default), unlike `authorizations:create` tokens.
- Tokens from `authorizations:create` have global scope in Heroku's example.
- The Heroku MCP server can use your CLI session (`heroku mcp:start`) or `HEROKU_API_KEY`.

## 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

### How do I get a Heroku API key?

Run `heroku authorizations:create -d "description"` for a non-expiring token, or `heroku auth:token` for a short-lived one.

### What is HEROKU_API_KEY?

It is the environment variable the Heroku CLI and Platform API clients use to hold a token.

### Why can't I create a Heroku token as an SSO user?

Federated accounts cannot issue OAuth authorizations. Heroku recommends a separate non-federated user to manage tokens.

### Can an AI agent use my Heroku 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://devcenter.heroku.com/articles/platform-api-quickstart
- https://devcenter.heroku.com/articles/heroku-mcp-server
