Payments and finance

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

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

TypePrefixSecret?ScopeExpiry
Personal access token
Each application has separate Production and Sandbox tokens.
—YesFull, 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.
—YesPermissions the seller granted during authorization30 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.

Open Square's key settings

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.

Rotation of personal access tokens is not documented on the access token page.

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 your Square key leaked

  1. Revoke OAuth tokens through RevokeToken.
  2. 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_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.

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:

IntentWhat BotPassword does
run_withRuns 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_requestMakes 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_secretSaves 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.

Stop pasting Square keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.