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

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

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Bot token | `xoxb-` | Yes | Acts as the app's bot user, limited to the bot scopes granted at install | No default expiry; optional token rotation gives 12-hour access tokens |
| User token | `xoxp-` | Yes | Acts on behalf of a workspace member, including the installer, limited to granted user scopes | No default expiry; optional token rotation gives 12-hour access tokens |
| App-level token | `xapp-` | Yes | Represents the app across organizations, for example for Socket Mode | Does not expire by default |
| Workflow token | `xwfp-` | Yes | A just-in-time subset of bot tokens that cannot perform user-scoped actions | Expires 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.

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

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

## Gotchas

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

## Using this key with AI agents (BotPassword)

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

## FAQ

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

## Sources

- https://docs.slack.dev/authentication/tokens
- https://docs.slack.dev/authentication/using-token-rotation
- https://docs.slack.dev/reference/methods/auth.test
- https://docs.slack.dev/reference/methods/auth.revoke
- https://docs.slack.dev/ai/slack-mcp-server
