API tokens

Endpoint: /api/auth/tokens/

Manage your personal API tokens. A personal token acts as you, within its scopes and your current roles. Token management shows only your own tokens. For automation that runs commands or transfers files, use a service token.

Authentication

Token management and token history require a signed-in session, through the web console or the CLI after alpacon login. Personal API tokens and service tokens receive 403 permission_denied on those routes. The scope and preset catalogs require authentication but do not require a signed-in session. All examples below use a signed-in session.

Use alpacon token to manage tokens from the CLI, or follow the console steps. The examples below require alpacon-cli 1.14.2 or later. Sign in to your workspace with alpacon login, then run alpacon api with your signed-in session. It prints the response body and prompts for MFA when needed.

Creating, duplicating and rotating personal tokens require a paid plan. Otherwise, the API returns 402 workspace_plan_update_required.

List API tokens

http
GET /api/auth/tokens/

Query parameters

ParameterTypeDescription
namestringExact token name
enabledbooleanEnabled status
searchstringSearch by name
orderingstringadded_at, updated_at, last_used_at; prefix - for descending. Default -updated_at
pageintegerPage number
page_sizeintegerResults per page (default 15, maximum 100)

Response

json
{
  "count": 1,
  "current": 1,
  "next": null,
  "previous": null,
  "last": 1,
  "results": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Inventory sync",
      "enabled": true,
      "scopes": [
        "server:read",
        "metric:read"
      ],
      "unreachable_scopes": [],
      "added_at": "2026-10-20T09:00:00Z",
      "updated_at": "2026-10-20T09:00:00Z",
      "expires_at": "2026-12-31T23:59:59Z",
      "last_used_at": null,
      "usage_count": 0
    }
  ]
}

Page links are integer page numbers. unreachable_scopes lists claimed scopes your current roles do not allow. Other scopes continue to work.

Example

bash
alpacon api -X GET "/api/auth/tokens/?enabled=true"

Rotate API token

http
POST /api/auth/tokens/{token_id}/rotate/

Replace the key on the same token. No request fields are needed. The old key stops authenticating immediately, and connections opened with it close. Update the stored secret as part of the same operation. usage_count resets to 0 and last_used_at to null.

Scopes stay unchanged and are not checked again for issuance. An existing expiry stays unchanged; a token without one receives the workspace maximum lifetime from now. An expired token cannot be rotated.

200 OK returns the token with its new key, using the same fields as creation.

bash
alpacon api -X POST "/api/auth/tokens/550e8400-e29b-41d4-a716-446655440000/rotate/"

Duplicate API token

http
POST /api/auth/tokens/{token_id}/duplicate/

Create a separate token while leaving the source key valid. The optional name is at most 128 characters. When omitted, the name is based on the source name with (copy) or a numbered copy suffix.

The copy keeps enabled and stored scopes except scopes personal tokens cannot be issued. If filtering removes every scope from a nonempty list, duplication fails with api_token_scopes_required. The copied expiry is limited to the workspace maximum. Server and file ACLs are copied; command ACLs are copied where command ACL writes are available. An expired source cannot be duplicated.

201 Created returns the new token and its one-time key, using the creation response fields.

bash
alpacon api -X POST \
  -f 'name=Inventory sync backup' \
  "/api/auth/tokens/550e8400-e29b-41d4-a716-446655440000/duplicate/"

Scope and preset catalogs

http
GET /api/auth/tokens/scopes/
GET /api/auth/tokens/presets/

Both return 200 OK without pagination. The scope response contains resources entries with name, actions and acl, limited to scopes your roles allow and the workspace offers for personal tokens. wildcards is an empty array, including for Superusers.

The preset response is an object keyed by preset ID. Each entry has name and description objects with en and ko, plus a permissions array. It filters out unavailable extensions and scopes personal tokens cannot carry. It does not filter by your roles; creation still checks your permission ceiling.

bash
alpacon api -X GET "/api/auth/tokens/scopes/"
bash
alpacon api -X GET "/api/auth/tokens/presets/"

Token history

http
GET /api/auth/token-history/
GET /api/auth/token-history/{history_id}/

Read changes to a token’s effective scopes after its owner’s roles change. Members see their own token history; admins see the workspace history. History remains readable after token deletion, with api_token: null and the saved api_token_name.

Query parameters

ParameterDescription
api_tokenExisting token ID; for a deleted token, filter by name or owner instead
api_token_name, token_userExact token name or owner ID
change_type, change_type__inExact change type or comma-separated types
added_at__gte, added_at__lteTime bounds
orderingadded_at or -added_at (default)
page, page_sizeInteger pagination; default 15 entries, maximum 100

List responses use count, current, next, previous, last, results. Each result, or the detail response, contains id, api_token, api_token_name, token_user, change_type, changes and added_at. A scope reduction is recorded in changes.effective_scopes.lost.

bash
alpacon api -X GET "/api/auth/token-history/?api_token_name=Inventory%20sync"

Error responses

StatusError codeDescription
400api_token_existsA token already has this name
400api_token_scope_invalidMalformed or unknown scope
400api_token_scope_exceeds_rbacScope exceeds your global role permissions
400api_token_scope_not_mintableScope or covering wildcard cannot be issued on a personal token
400api_token_scopes_requiredDefault, preset or duplicate processing produced no usable scopes
400api_token_invalid_presetUnknown preset or its extension is off
400api_token_presets_not_allowed_on_updateUse scopes, not presets, on update
400api_token_invalid_expirationExpiry is in the past
400api_token_expires_exceeds_max_ttlExpiry exceeds the workspace maximum lifetime
400api_token_already_expiredExpired tokens cannot be revived, widened, duplicated or rotated
400api_token_scope_expansion_pendingA scope expansion already awaits approval
401auth_token_missingNot authenticated, or credential is invalid or expired
402workspace_plan_update_requiredCreate, duplicate and rotate require a paid plan
403permission_deniedManagement or history requested with a personal or service token
403workspace_suspendedWrites refused while the workspace is suspended
404api_not_foundToken or history entry is not accessible or does not exist
Last updated: