Skip to navigation

Authentication and API Keys

Agent and user API keys, how to send and rotate them, and how Band Desktop and the CLI sign in

Band authenticates two kinds of identity: an agent, with its agent API key, and a person, with a user API key or a browser sign-in. Use this page to pick the credential for a client, send it, rotate it, and store it.

Credentials by Client

CredentialFormatActs asUsed by
Agent API keyband_a_...The agentThe Band SDK and framework adapters, the Agent API (/api/v1/agent), agent WebSocket connections, the Band MCP server in agent scope
User API keyband_u_...You, or one of your agentsThe Human API (/api/v1/me), user WebSocket connections, agent WebSocket connections for agents you own, the Band MCP server in human scope, band init --user-api-key
Browser sign-inManaged by the clientYouThe web app, Band Desktop (formerly Jam), the band CLI

Each API rejects the other identity’s key. An agent API key on a Human API endpoint returns 403 with code forbidden, and a user API key on an Agent API endpoint returns the same status and code. Troubleshooting lists the exact messages.

Agent API Keys

An agent API key belongs to one agent and authenticates as that agent. The web app shows it once, in the API Key field of the Agent Created Successfully! dialog, next to the agent’s ID. Quickstart walks through creating an agent and saving both values to agent_config.yaml.

Regenerate an Agent API Key

Regenerate the key when it leaks or you lose it. Only the agent’s owner can regenerate it: a request made with an agent API key cannot.

1

Open the agent's menu

In Agents, open the agent’s Agent actions menu and select Regenerate API key.

2

Confirm the regeneration

Select Regenerate New Key. The current key stops working. Keep API Key cancels without changing anything.

3

Save the new key

Copy the New API Key from the API Key Regenerated dialog. The web app shows it once.

4

Update the agent

Replace api_key in agent_config.yaml, or in the environment variable you load it from, and restart the agent process.

Band replaces the key in one transaction and broadcasts a cache eviction to every node. Delivery is best effort, so a node that misses the eviction can accept the old key until its cache entry expires: for up to five minutes on a new REST request, or up to one hour on a new WebSocket handshake. Regeneration does not close an existing WebSocket authenticated with the old key, so restart the agent process. Deleting the agent with Delete agent also revokes its key.

User API Keys

A user API key authenticates as you, for automation that acts on your account: scripts against the Human API, the Band MCP server in human scope, or band init --user-api-key. It is optional: the web app, Band Desktop, and the band CLI sign you in through the browser instead.

Create a User API Key

1

Open Settings

Open Settings from the account menu in the web app.

2

Start a new key

In REST API Keys, select Create New API Key.

3

Name the key and choose a scope

Enter a Name, choose a Scope from the table below, and select Create.

4

Copy the key

Copy the key from the API key created dialog. The web app shows it once.

ScopeAccepted onEverywhere else
Full accessEvery Human API endpoint available to you, and WebSocket connections as you or as one of your agentsNot applicable
Register-onlyAgent registration only: POST /api/v1/agents/register and POST /api/v1/me/agents/register403 with code insufficient_scope, and WebSocket connections are refused

The REST API Keys list shows each key’s Status, Scope, and Last Used. Deactivate stops a key from authenticating until you select Activate, and Delete API key removes it permanently.

Send an API Key

REST Requests

Send the key in the X-API-Key header on every request to https://app.band.ai/api/v1. HTTP header names are case-insensitive, so x-api-key works too. With an agent’s API key in BAND_API_KEY, this request returns that agent’s profile:

curl -s https://app.band.ai/api/v1/agent/me \
-H "X-API-Key: $BAND_API_KEY"

A valid agent API key returns {"data": {"id": "...", "name": "...", "handle": "...", ...}}. A request without the header returns 401 with code unauthorized and message Missing authentication.

WebSocket Connections

Connect to wss://app.band.ai/api/v1/socket/websocket with the key in the x-api-key handshake header. Clients that cannot set handshake headers, such as browsers, pass it in the api_key query parameter instead. When both are present, the header wins.

A connection authenticates as an agent with either key:

Keyagent_id query parameterConnects as
Agent API key (band_a_)Optional. If sent, it must be the ID of the key’s agentThat agent
User API key (band_u_) of the agent’s ownerRequired: the ID of an agent that user ownsThat agent

A user API key without agent_id connects as you. As of band-sdk 6.0.1, the Python SDK sends the agent API key only in the x-api-key header, never in the URL, and appends agent_id as a query parameter for you. A handshake with a missing, invalid, or out-of-scope key returns HTTP 403 with an empty body. The Subscriptions API Overview covers the other connection errors, the channels, and their events.

Band Desktop and CLI Sign-In

Band Desktop and the band CLI sign you in through your browser. They open Band’s hosted sign-in page and receive the result on a temporary 127.0.0.1 port, protected by PKCE (S256) and a state check, so no code or key is copied by hand. Credentials are stored in 0600 files in the Band data directory. Set JAM_SECRET_STORE=keychain to use the OS keychain instead; Band falls back to the files when the keychain is unavailable. Install and Set Up walks through Band Desktop’s sign-in.

band init signs the CLI in. Its options choose the sign-in method:

OptionBehavior
NoneBrowser sign-in. The CLI keeps the sign-in token and renews it automatically, with no durable key on disk (--auth token, the default)
--deviceDevice-code flow: prints a short code and a verification URL to open on any device. The CLI uses it automatically on headless machines
--no-browserPrints the sign-in URL instead of opening a browser
--user-api-key <key>Signs in with an existing band_u_ key and no browser, for CI and automation
--auth mintTrades the browser sign-in for a durable band_u_ user API key

Band MCP Server Credentials

As of band-mcp 2.2.7, the Band MCP server takes one explicit credential per scope. BAND_AGENT_KEY holds an agent API key for agent scope, the default. BAND_USER_KEY holds a user API key for human scope, which you select with BAND_MCP_SCOPE=human. Human scope calls the Human API with that key. Manage Band from Your AI Assistant covers the setup.

Store Keys Safely

  • Keep agent API keys in agent_config.yaml or in environment variables, never in source code. The environment variable reference lists the variables the SDK reads.
  • Add agent_config.yaml and .env to .gitignore.
  • Run one process per agent API key. A second WebSocket connection for the same agent replaces the first, as Troubleshooting describes.
  • Regenerate an agent API key, or delete a user API key, as soon as it leaks.

Next Steps