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.
Square key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Personal access token Each application has separate Production and Sandbox tokens. | — | Yes | Full, unscoped access to your own Square account | — |
| OAuth access token Short-lived tokens expiring after 24 hours can be requested with short_lived set to true. | — | 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
- Sign in to the Square Developer Console and open your application.
- Choose Credentials in the left pane.
- Use the Production switch at the top to choose Sandbox or Production.
- 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
- For OAuth tokens, call
ObtainTokenwithgrant_typeset torefresh_tokenbefore the access token expires.
Rotation of personal access tokens is not documented on the access token page.
How to revoke a Square key
- Call the OAuth
RevokeTokenendpoint (/oauth2/revoke) to revoke a seller authorization. - Set
revoke_only_access_tokento true to revoke just one access token and keep the authorization.
If your Square key leaked
- Revoke OAuth tokens through
RevokeToken. - Replace and redeploy any personal access token using the Developer Console credentials page.
Environment variables and CLI
Square's SDKs and docs read the key from ACCESS_TOKEN.
Things that catch people out
ACCESS_TOKENis 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 takesACCESS_TOKEN,SANDBOXandPRODUCTION. - Webhook Subscriptions and Events APIs require a personal access token.
Common Square authentication errors
AUTHENTICATION_ERROR (code UNAUTHORIZED)
A token for the wrong environment was used, for example a Sandbox token against the production base URL.
Using your Square 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 Square 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. |
store_secret | Saves a value the agent already holds as a new vault item. |
Square 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
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.