Cloud and hosting

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

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.

Heroku key types

TypePrefixSecret?ScopeExpiry
Authorization token (non-expiring)
Federated (SSO) accounts cannot create these.
HRKU-Yesglobal (as created by `heroku authorizations:create`)Does not expire
CLI token
Printed by heroku auth:token.
—YesYour accountValid 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 your Heroku 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 and CLI

Heroku's SDKs and docs read the key from HEROKU_API_KEY.

Heroku CLI (heroku): heroku login opens a browser sign-in; scripts can use HEROKU_API_KEY

Things that catch people out

  • 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.

Common Heroku authentication errors

This account is a federated account. Federated accounts cannot issue OAuth authorizations.

You tried to create a non-expiring token from a federated (SSO) account.

Using your Heroku key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a Heroku key, these intents fit:

IntentWhat BotPassword does
list_credentialsLists the credentials this agent is granted and what it may do with each. Never values.
run_withRuns 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_requestMakes 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_loginLets 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.
rotatePartly 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_secretSaves a value the agent already holds as a new vault item.

Heroku also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

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.

Stop pasting Heroku keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.