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.
Mapbox key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Public token Can be restricted to allowed URLs. | pk. | No | Public scopes only, such as `styles:read` and `fonts:read` | — |
| Secret token Shown only once at creation. | sk. | Yes | Secret scopes such as uploads, tilesets and tokens | — |
| Temporary token Does not appear on the Access Tokens page. | tk. | Yes | Set when created through the Tokens API | Up to 1 hour ahead |
How to create a Mapbox key
- Sign in to Mapbox and open the Access Tokens page.
- Create a token and tick only the scopes it needs.
- For a public token, add allowed URLs.
- 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
- Create a new token.
- Replace it in your code.
- Redeploy.
- Delete the old token.
Invalidation is immediate for uncached requests; cached responses persist for a period that varies by service. Trial accounts cannot create, rotate or delete tokens until a payment method is added.
How to revoke a Mapbox key
- Delete the token on the Access Tokens page. Deletion is permanent.
If your Mapbox key leaked
- Create a replacement token with the same scopes.
- Deploy it and delete the exposed token.
- Check usage for unexpected requests.
Things that catch people out
- 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.
Common Mapbox authentication errors
403: Forbidden
A URL-restricted token was used from a URL that is not on its allowed list.
Using your Mapbox 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 Mapbox key, these intents fit:
| Intent | What BotPassword does |
|---|---|
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. |
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
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.