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

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

Square access tokens are found in the Developer Console under your application's **Credentials** page, with separate Sandbox and Production tokens. A personal access token gives full access to your own account; OAuth tokens are scoped and must be refreshed.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Personal access token | — | Yes | Full, unscoped access to your own Square account | — |
| OAuth access token | — | Yes | Permissions the seller granted during authorization | 30 days after creation; Square recommends refreshing every 7 days or less |

## How to create a Square key

1. Sign in to the Square Developer Console and open your application.
2. Choose **Credentials** in the left pane.
3. Use the **Production** switch at the top to choose Sandbox or Production.
4. Copy the access token.

## Limiting what the key can do

Personal access tokens are unscoped. For limited access use OAuth, where sellers grant specific permissions and you can limit scopes.

## How to rotate a Square key

1. For OAuth tokens, call `ObtainToken` with `grant_type` set to `refresh_token` before the access token expires.

## How to revoke a Square key

1. Call the OAuth `RevokeToken` endpoint (`/oauth2/revoke`) to revoke a seller authorization.
2. Set `revoke_only_access_token` to true to revoke just one access token and keep the authorization.

## If the key leaked

1. Revoke OAuth tokens through `RevokeToken`.
2. Replace and redeploy any personal access token using the Developer Console credentials page.

## Environment variables

- `ACCESS_TOKEN`

## Gotchas

- `ACCESS_TOKEN` is the variable name for Square's local MCP server; the docs do not define a standard name for SDK use.
- The remote Square MCP server (`https://mcp.squareup.com/mcp`) uses OAuth and reaches production only; the local server takes `ACCESS_TOKEN`, `SANDBOX` and `PRODUCTION`.
- Webhook Subscriptions and Events APIs require a personal access token.

## 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.
- `store_secret`: Saves a value the agent already holds as a new vault item.

## FAQ

### Where do I find my Square access token?

In the Developer Console, open your application and choose **Credentials**; switch between Sandbox and Production at the top.

### How long do Square OAuth tokens last?

30 days after creation. Refresh them with `ObtainToken` and `grant_type=refresh_token`, ideally every 7 days or less.

### Does Square have an MCP server?

Yes. A remote server at `https://mcp.squareup.com/mcp` uses OAuth, and a local server uses an access token in `ACCESS_TOKEN`.

### Can an AI agent use my Square 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://developer.squareup.com/docs/build-basics/access-tokens
- https://developer.squareup.com/docs/oauth-api/refresh-revoke-limit-scope
- https://developer.squareup.com/docs/mcp
