# Authentication

> Personal API tokens - how to create one, the scopes, project limits and expiry, what a token can never do, and how the dashboard session differs.

Requests from scripts, CI and agents use a **personal API token**:

```http
Authorization: Bearer mly_…
```

A token is `mly_` and 43 letters and digits. Only its SHA-256 is stored; the value is shown once, when it is made.

## Creating a token

In the dashboard, **Settings → API tokens → Create token**: choose a name, the scopes, optionally one project, and optionally an expiry. Any workspace member can make tokens for themselves; how many active tokens a workspace has depends on its plan ([Plans and limits](https://docs.monitorly.cloud/concepts/plans.md)).

Tokens are managed only from a signed-in session: a token cannot create, list or revoke tokens.

## What a token may do

A token acts as the person who made it, with three limits:

- **Scopes.** `GET` requests need the `…:read` scope of their area, other methods the `…:write` one. `:write` does not include `:read`.
- **Project.** A token for one project sees only that project; anything else answers 404. At workspace level it acts no higher than a member.
- **The creator's role, now.** A token never has more rights than its creator has at the time of each request. If the creator leaves the workspace, the token stops working.

| Scope                                   | Covers                                                                      |
| --------------------------------------- | --------------------------------------------------------------------------- |
| `checks:read`, `checks:write`           | Checks, runs, response times, uptime reports, test runs, heartbeat URLs     |
| `incidents:read`, `incidents:write`     | Incidents, acknowledging, incident post drafts                              |
| `maintenance:read`, `maintenance:write` | Maintenance windows                                                         |
| `pages:read`, `pages:write`             | Status pages, components, incident posts                                    |
| `nodes:read`, `nodes:write`             | Nodes, join tokens, revoking, locations; servers and their metrics (read)   |
| `alerts:read`, `alerts:write`           | Alert channels, escalation policies, a project's or a check's policy        |
| `telegram:read`                         | Linked Telegram chats                                                       |
| `projects:write`                        | Creating a project (workspace owner or admin, not with a one-project token) |

Workspaces, projects, plan limits and billing state can be read by any token. Config export, plan and apply need the scope of each section the `monitorly.yaml` has (`checks:*`, `maintenance:*`, `pages:*`). A missing scope answers `403 token.scope_missing`; its `detail` names the scope (`this token needs the scope checks:write`).

## What a token can never do

These need a signed-in person and answer `403 token.not_allowed` to a token: signing in and out, the profile, email address, password and two-factor settings, account deletion and data exports, members, invites and project members, creating, changing, transferring, exporting or deleting workspaces, renaming or deleting projects, API tokens themselves, billing changes, Telegram link codes, test messages and unlinking, status page email subscribers, previews and access tickets, the agents' consent screen, the event stream and the audit log. Each operation of the [REST reference](https://docs.monitorly.cloud/api/reference.md) shows which sign-in it takes.

## The CLI's sign-in

`monitorly login` signs the CLI in with OAuth in the browser instead of a token you paste. The REST API accepts that sign-in as it accepts a token, with the scopes you approved. OAuth sign-ins of other agents work only on the [MCP server](https://docs.monitorly.cloud/mcp/oauth.md); on the REST API they answer `401 token.invalid`.

## Invalid tokens

`401 token.invalid` means the token is malformed, unknown, revoked or expired, its creator is no longer a member, or the `Authorization` header is not exactly one `Bearer` header in ASCII. A request that carries both a session cookie and a token is refused with `400 auth.credentials_conflict`.

## Revoking

Revoke a token under **Settings → API tokens**. It stops working at once. Its creator, or a workspace owner or admin, can revoke it.

## The dashboard session

The dashboard signs in with a session cookie that ends after 7 days without use and 30 days after sign-in. Changing requests from a session must come from the dashboard's own origin and carry `X-Monitorly-Request: 1`; requests with a token need neither.

## Audit

Every change is recorded in the workspace's audit log with who made it and how: `ui` for the dashboard, `api` for a token, `cli` and `mcp` for the CLI and MCP clients.
