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

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

Mapbox has public tokens (`pk.`) for client-side code, secret tokens (`sk.`) for servers, and temporary tokens (`tk.`) that expire within an hour. Manage them on the Access Tokens page in the Developer Console.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Public token | `pk.` | No | Public scopes only, such as `styles:read` and `fonts:read` | — |
| Secret token | `sk.` | Yes | Secret scopes such as uploads, tilesets and tokens | — |
| Temporary token | `tk.` | Yes | Set when created through the Tokens API | Up to 1 hour ahead |

## How to create a Mapbox key

1. Sign in to Mapbox and open the [Access Tokens page](https://console.mapbox.com/account/access-tokens/).
2. Create a token and tick only the scopes it needs.
3. For a public token, add allowed URLs.
4. Copy the value; a secret token can be viewed only once.

## Limiting what the key can do

Use the fewest scopes needed. Secret scopes cannot be added to a `pk` token; create a new `sk` token instead. A token cannot be created with more scopes than the token that creates it. URL restrictions (up to 100 URLs) are best-effort and do not support wildcards, IP addresses or mobile SDK apps.

## How to rotate a Mapbox key

1. Create a new token.
2. Replace it in your code.
3. Redeploy.
4. Delete the old token.

## How to revoke a Mapbox key

1. Delete the token on the Access Tokens page. Deletion is permanent.

## If the key leaked

1. Create a replacement token with the same scopes.
2. Deploy it and delete the exposed token.
3. Check usage for unexpected requests.

## Gotchas

- A secret `sk.` token is shown only once.
- If you refresh the default public token, Mapbox generates a new one.
- Cached responses may keep working briefly after a token is deleted.

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

## FAQ

### What is the difference between a Mapbox public and secret token?

Public tokens start with `pk.` and belong in client code. Secret tokens start with `sk.` and must stay on a server.

### Where do I create a Mapbox access token?

On the Access Tokens page of the Developer Console.

### How do I rotate a Mapbox token?

Create a new one, replace it, redeploy, then delete the old token.

### Can an AI agent use my Mapbox 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`, so the agent gets the result and never the value.

## Sources

- https://docs.mapbox.com/accounts/guides/tokens/
