# Access tokens and scopes

Source: https://tiltas.openpanel.sh/docs/ai/tokens

> Scoped tokens for scripts, CI and agents that cannot sign in with OAuth, on the REST API and the MCP server.

An **Access token** is for software that runs without a person: a script, a CI job, a headless agent. It works on the
[REST API](/docs/api) and on the MCP server, for one Network. An app that can open a browser should connect with
[OAuth](/docs/ai) instead: its tokens last an hour and renew themselves.

## Create one

In the console, open **Enterprise → Access tokens**, or call the API from a signed-in session:

```bash
curl -X POST https://tiltas.openpanel.sh/api/v1/accounts/$ACCOUNT/access-tokens \
  -H 'Content-Type: application/json' \
  -d '{"name": "deploy pipeline", "scopes": ["services:write"], "expires_in_days": 30}'
```

- `scopes`: what it may do (below). `read` is always added.
- It lasts **90 days** unless you set `expires_in_days` (1 to 365) or `"never_expires": true`.
- The secret (`qlt_…`) is shown once. Store it in a secret manager.

Only Owners and Admins make tokens, and a token works only while the person who made it is still an Owner or Admin of
the Network. A token never does what only an Owner may (billing, deleting the Network) and never makes other tokens.

## Scopes

Some changes wait for a person's [approval](/docs/ai/approvals). That happens on the MCP server, where the agent gets
a link for an Owner or Admin. On the REST API nobody is asked, so a scoped token cannot make those changes there (see
[On the REST API](#on-the-rest-api)).

| Scope | Runs at once | Waits for a person through the MCP |
| --- | --- | --- |
| `read` | every read: Devices, Services, rules, Groups, people, status, usage, the audit log | |
| `network:write` | rename the Network, change key expiry and alerts | turning device approval off, creating another Network |
| `devices:write` | rename Devices | approving a Device, adding Groups or subnet routes, turning on an exit node, stopping key expiry |
| `devices:remove` | | removing a Device |
| `joinkeys:write` | single-use keys that last up to an hour, revoking keys | reusable keys, longer ones, keys that put servers into Groups |
| `services:write` | creating and changing Services only the token's person may use | sharing a Service with others, pointing a shared one elsewhere, deleting |
| `rules:write` | creating Groups, narrowing rules and Groups | new Access and SSH rules, changes that widen access, deletes |
| `members:write` | revoking invites | invites, role changes, removing people |
| `network:delete` | | deleting the Network; only an Owner approves it |

Tokens made before scopes existed carry `read` or `write`. They keep working: `write` allows every write an Admin may
make, at once, as before. Prefer the narrow scopes for new tokens.

A call outside the token's scopes answers `403` with the scope it needs:

```json
{ "status": 403, "code": "access_denied", "detail": "This Access token does not have the joinkeys:write scope." }
```

## On the REST API

A scoped token gets `403 access_denied` for anything in the last column, and the detail says the change waits for a
person. Ask for it through the MCP server instead, or make it in the console. The REST API judges from the request
alone, so it is stricter than the MCP, which compares with what is there now:

- Changing an Access rule, Group or SSH rule is refused: each request replaces the whole object.
- On a Device, only `name`, `exit_node: false` and `key_expiry_disabled: false` run.
- A Join key runs only single-use, with `expires_in_minutes` up to 60 and no Groups. Without `expires_in_minutes` it
  would last 7 days, so it is refused.
- A Service's `allowed` may name only the token's own person, or nobody; a new `target` or `ports` is refused.
- A field the API does not list as safe is refused.

```bash
curl -X POST https://tiltas.openpanel.sh/api/v1/accounts/$ACCOUNT/join-keys \
  -H "Authorization: Bearer $TILTAS_TOKEN" -H 'Content-Type: application/json' \
  -d '{"name": "ci runner", "expires_in_minutes": 15}'
```

## On the MCP server

Send the token as a Bearer token (see **Other clients** on [Use with AI](/docs/ai)). The same
[approvals](/docs/ai/approvals) apply: a token with `devices:remove` can ask to remove a Device; a person still
approves it. If the token is revoked first, or its maker leaves the Network or stops being an Admin, the request can no
longer be approved.

## OAuth tokens

Tokens that MCP clients get through OAuth use the same prefix but are issued for the MCP server alone: the REST API
refuses them. They last one hour; the client renews them with a refresh token that changes on every use. If a refresh
token is ever used twice, Tiltas ends the whole connection.
