Email, messaging and chat

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

Slack apps use several token types identified by prefix: bot tokens (xoxb-), user tokens (xoxp-) and app-level tokens (xapp-). Bot and user tokens do not expire unless you opt into token rotation, which makes access tokens last 12 hours and refresh tokens single-use.

Slack key types

TypePrefixSecret?ScopeExpiry
Bot tokenxoxb-YesActs as the app's bot user, limited to the bot scopes granted at installNo default expiry; optional token rotation gives 12-hour access tokens
User tokenxoxp-YesActs on behalf of a workspace member, including the installer, limited to granted user scopesNo default expiry; optional token rotation gives 12-hour access tokens
App-level token
The opt-in rotating variant uses the prefix xoxe.xapp-, with access tokens that expire after 12 hours and single-use refresh tokens.
xapp-YesRepresents the app across organizations, for example for Socket ModeDoes not expire by default
Workflow tokenxwfp-YesA just-in-time subset of bot tokens that cannot perform user-scoped actionsExpires 15 minutes after issue, or when the function step completes or errors; cannot be refreshed

How to create a Slack key

  1. Create or open your app in the Slack app management console at api.slack.com/apps.
  2. Add the scopes your app needs, then install it to the workspace.
  3. Copy the issued bot or user token from the app's settings.

Open Slack's key settings

Limiting what the key can do

A token can only do what its granted OAuth scopes allow. Request the narrowest bot scopes at install, and prefer a bot token over a user token so the app does not act as a person. The official Slack MCP server requires user-token scopes per tool (for example chat:write).

How to rotate a Slack key

  1. Enable token rotation for the app, then exchange the existing long-lived token once with oauth.v2.exchange.
  2. Refresh before the 12-hour expiry by calling oauth.v2.access with grant_type=refresh_token; each response returns a new access and refresh token.
  3. Save the new refresh token every time; each one is single-use.
  4. Call auth.revoke on the old access token to invalidate it immediately.

Refreshing does not immediately invalidate the previous access token. Only two active tokens are kept if you refresh repeatedly within 12 hours. Token rotation is opt-in and cannot be turned off once on.

How to revoke a Slack key

  1. Call auth.revoke with the token. For a bot token this deactivates the bot user and removes its channel memberships but does not uninstall the app.
  2. To get a new bot token, run the OAuth install flow again; single-workspace apps can read the new token in the app management console.
  3. apps.uninstall removes the app and revokes all tokens for the installation.

If your Slack key leaked

  1. Revoke the token with auth.revoke, or uninstall the app with apps.uninstall.
  2. Reinstall or re-run OAuth to obtain a new token, then update every deployment.
  3. Review the app's recent actions in the workspace.

Environment variables and CLI

Slack CLI (slack)

Things that catch people out

  • Bot tokens never expire unless you enable token rotation, so a leaked token stays valid until revoked.
  • auth.revoke on a bot token deactivates the bot user; it does not uninstall the app.
  • The Slack MCP server uses OAuth with a registered app; only directory-published or internal apps can use it.
  • Org-wide apps must be removed by an org admin in the admin console.

Common Slack authentication errors

invalid_auth

The credentials are invalid, the token cannot be validated, or the request came from a disallowed IP address.

not_authed

The request did not include an authentication token.

token_revoked

For a user token, the user or workspace was deleted or the app was removed.

Recent incidents that put Slack keys at risk

If you were affected by one of these, rotate your Slack keys using the rotation steps above.

Using your Slack 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 Slack key, these intents fit:

IntentWhat BotPassword does
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.
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.
capture_secretPlanned, not built yet: will read a newly created key straight from the page or command output into the vault.

Slack 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

What is a Slack bot token?

A token starting xoxb- that represents your app's bot user, with the scopes you granted at install.

What is the difference between xoxb and xoxp?

xoxb- acts as the bot user; xoxp- acts on behalf of a workspace member, including the installer.

Do Slack tokens expire?

Not by default. If you opt into token rotation, access tokens expire after 12 hours and are refreshed with single-use refresh tokens.

Can an AI agent use my Slack 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 run_with, http_request, store_secret, so the agent gets the result and never the value.

Stop pasting Slack keys into agents

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