API tokens
Bearer tokens for the CLI, scripts, agents and MCP. How they authenticate and how scopes combine: Authentication.
The first token must be created from a session (the console, or
POST /v1/auth/login + X-Mayadyn-Tenant), because creating a token
needs an authenticated caller with admin. A token with admin can then
create further tokens.
GET /v1/tokens
Section titled “GET /v1/tokens”List the workspace’s tokens, newest first, including revoked and expired ones.
Auth: scope admin. A project token sees only tokens of its project.
Response 200:
{"items": [ {"id": "7a8b9c0d-1e2f-4a3b-9c4d-5e6f7a8b9c0d", "name": "ci-deploy", "prefix": "myd_gsvtdw", "user_id": "2b8e7c41-5d0a-4f3e-8c6b-9e1f2a3d4c5b", "user_email": "sara@acme.example", "project_id": "0c9d8e7f-1a2b-4c3d-8e5f-6a7b8c9d0e1f", "scopes": ["read", "write"], "expires_at": "2027-02-28T09:00:00Z", "last_used_at": "2026-11-30T08:59:12Z", "created_at": "2026-11-30T09:00:00Z"}, {"id": "b0c1d2e3-f4a5-4b6c-8d7e-9f0a1b2c3d4e", "name": "old-laptop", "prefix": "myd_a7b2cd", "user_id": "2b8e7c41-5d0a-4f3e-8c6b-9e1f2a3d4c5b", "user_email": "sara@acme.example", "scopes": ["read"], "revoked_at": "2026-11-15T10:00:00Z", "created_at": "2026-10-03T10:00:00Z"}]}scopes is what the token was given; its effective scopes may be fewer
(creator’s current role). user_* is the person who created it (directly,
or through a parent token).
POST /v1/tokens
Section titled “POST /v1/tokens”Create a token. The secret is returned once.
Auth: scope admin (session or token).
Request body (CreateTokenRequest)
| Field | Type | Required | Description |
|---|---|---|---|
name |
string | yes | 1–100 characters (trimmed) |
scopes |
string[] | yes | non-empty subset of read, write, destroy, admin; each must be one the caller has |
project_id |
string (UUID) | no | limit the token to this project. Forced to the caller’s project when the caller is a project token |
expires_in_days |
integer | no | expiry in days from now; omitted, 0 or negative: no expiry. Capped at the parent token’s expiry when created by a token |
{"name": "ci-deploy", "scopes": ["read", "write"], "project_id": "0c9d8e7f-1a2b-4c3d-8e5f-6a7b8c9d0e1f", "expires_in_days": 90}Response 201 (NewAPIToken):
{"id": "7a8b9c0d-1e2f-4a3b-9c4d-5e6f7a8b9c0d", "name": "ci-deploy", "prefix": "myd_gsvtdw", "user_id": "2b8e7c41-5d0a-4f3e-8c6b-9e1f2a3d4c5b", "user_email": "", "project_id": "0c9d8e7f-1a2b-4c3d-8e5f-6a7b8c9d0e1f", "scopes": ["read", "write"], "expires_at": "2027-02-28T09:00:00Z", "created_at": "2026-11-30T09:00:00Z", "secret": "myd_gsvtdwl3yesjionebftrhzxike7c7sz3j7zh7434o76ruhpg6i3q"}user_email is empty in this response (it is filled in lists).
Errors
| Status | Code | When |
|---|---|---|
| 400 | invalid_input |
name missing or too long; no scopes; unknown scope; project_id not a UUID |
| 403 | permission_denied |
no admin; “you cannot grant the X scope you do not have”; “a project token can only create tokens for its own project” |
| 404 | not_found |
“project not found” |
Notes
- The token belongs to the workspace the request acts in.
- It records how the creating session signed in (its
amr); a child token inherits its parent’s. Workspace MFA/SSO rules judge the token by this (Authentication). - A token created by a token never outlives its parent and stops working when the parent is revoked or expires.
- Audit:
token.createwithscopesandname.
curl -s -X POST "$MAYADYN/v1/tokens" -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"name":"ci-deploy","scopes":["read","write"],"expires_in_days":90}'From the console session:
curl -s -b jar -X POST "$MAYADYN/v1/tokens" \ -H "X-Mayadyn-Tenant: acme" -H "X-Mayadyn-CSRF: 1" -H "Content-Type: application/json" \ -d '{"name":"laptop","scopes":["read","write","destroy"]}'DELETE /v1/tokens/{id}
Section titled “DELETE /v1/tokens/{id}”Revoke a token.
Auth:
| Caller | May revoke |
|---|---|
any caller with admin |
any token in its scope (a project token: tokens of its project) |
a person’s session without admin |
their own tokens |
a token without admin |
itself only |
| Param | In | Description |
|---|---|---|
id |
path | token UUID |
Response 204. Revoking an already revoked token also succeeds.
Errors: 404 “token not found” (also another project’s token, for a
project token); 403 permission_denied “this action needs the admin
permission”.
Notes: tokens created by the revoked token (and their children) stop
working too. Audit: token.revoke.
curl -s -X DELETE "$MAYADYN/v1/tokens/7a8b9c0d-1e2f-4a3b-9c4d-5e6f7a8b9c0d" \ -H "Authorization: Bearer $TOKEN"