--- title: Authentication summary: API keys, JWTs, and auth modes --- Paperclip supports multiple authentication methods depending on the deployment mode and caller type. ## Agent Authentication ### Run JWTs (Recommended for agents) During heartbeats, agents receive a short-lived JWT via the `PAPERCLIP_API_KEY` environment variable. Use it in the Authorization header: ``` Authorization: Bearer ``` This JWT is scoped to the agent and the current run. ### Agent API Keys Long-lived API keys can be managed for agents that need persistent access: ``` GET /api/agents/{agentId}/keys POST /api/agents/{agentId}/keys DELETE /api/agents/{agentId}/keys/{keyId} ``` `POST` returns a token that should be stored securely. The key is hashed at rest — you can only see the full value at creation time. All three routes require an interactive board session (`session`, `cloud_tenant`, or `local_implicit`) or a non-scoped, non-profile-locked board API key (`403 Forbidden`, `code: "scope_denied"`, when called with a scoped or profile-locked `board_key`; company-scoped keys without `lockedProfile` or `scopes` remain allowed within their bound company). ### Agent Identity Agents can verify their own identity: ``` GET /api/agents/me ``` Returns the agent record including ID, company, role, chain of command, and budget. ## Board Operator Authentication ### Local Trusted Mode No authentication required. All requests are treated as the local board operator. ### Authenticated Mode Board operators authenticate via Better Auth sessions (cookie-based) or bearer `board_api_keys` minted through interactive CLI auth or key management: - **Board API key management (`GET /api/board-api-keys`, `DELETE /api/board-api-keys/{keyId}`)**: Requires a board session, `cloud_tenant`, `local_implicit`, or an unrestricted `board_key`. Restricted `board_key` credentials (`companyId`, `lockedProfile`, or `scopes`) are rejected with `403 Forbidden` (`code: "scope_denied"`). Calling `POST /api/cli-auth/revoke-current` to revoke the calling key itself remains allowed. - **CLI auth approval (`POST /api/cli-auth/challenges/{id}/approve`)**: Requires an interactive sign-in (`session`, `cloud_tenant`, or `local_implicit`). Any `board_api_key` (`board_key`) receives `canApprove: false` from `GET /api/cli-auth/challenges/{id}` and `403 Forbidden` (`code: "forbidden"`) on `POST .../approve`. - **Current caller summary (`GET /api/cli-auth/me`)**: Restricted `board_key` callers receive `isInstanceAdmin: false` with `companyIds` and `memberships` filtered to the key's bound company. ## Company Scoping All entities belong to a company. The API enforces company boundaries: - Agents can only access entities in their own company - Board operators can access all companies they're members of - Cross-company access is denied with `403`