---
title: luna tokens
description: Make, list, rotate and revoke API tokens for CI and platforms, and the account keys that act as you.
related:
  - /platforms/automate-with-api-tokens
  - /concepts/keys-and-tokens
  - /develop/deploy-from-ci
---

`luna tokens` manages API tokens, which a program uses to reach the management API, and the account keys that act as you.

```bash
luna tokens create --name ci --scope deploy:write --project acme/notes
```

## Reference

```bash
luna tokens <COMMAND>
```

Every subcommand takes `--token <TOKEN>`, the API token or account key to act with. It defaults to `LUNA_TOKEN`, then your login.

### luna tokens create

Makes an API token for one project or a whole organisation, and prints it once. With `--account` it makes an account key instead.

```bash
luna tokens create [OPTIONS]
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `--scope <SCOPE>` | text, repeatable | Required without `--account` | A permission the token holds. The scopes are listed below. |
| `--name <NAME>` | text | Empty | A name to tell it by. An account key needs one. |
| `--project <PROJECT>` | text | `LUNA_PROJECT` | The project the token reaches, as `organisation/project`. |
| `--org <ORG>` | text | None | An organisation instead, for a token that reaches every project in it. |
| `--env <ENV>` | text, repeatable | Every environment | Limits the token to this environment of the project. |
| `--expires-in <EXPIRES_IN>` | duration | Never | The token stops working after this long, such as `90m` or `30d`, or a number of seconds. |
| `--account` | flag | Off | Makes an account key instead. It acts as you, with your role in each organisation, and only reads. |
| `--write` | flag | Off | With `--account`, the key also changes things. |

`--account` cannot be given with `--scope`, `--project`, `--org` or `--env`. `--org` cannot be given with `--project` or `--env`.

### luna tokens list

Prints the API tokens you look after: each one's id, name, what it reaches, its scopes and when it was last used. With `--account` it prints your account keys instead.

```bash
luna tokens list [OPTIONS]
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `--account` | flag | Off | Lists your account keys, with their access, last use and expiry. |
| `--json` | flag | Off | Prints the answer as JSON. |

### luna tokens rotate

Makes a replacement API token with the same scopes and reach, and prints it once. The old token goes on working for the overlap.

```bash
luna tokens rotate [OPTIONS] <ID>
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `<ID>` | text | Required | The token's id, from `luna tokens list`. |
| `--overlap <OVERLAP>` | duration | `1h` | How long the old token goes on working, such as `1h` or `2d`, or a number of seconds. |

### luna tokens revoke

Stops a token working at once.

```bash
luna tokens revoke [OPTIONS] <ID>
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `<ID>` | text | Required | The token's id, or the account key's with `--account`. |
| `--account` | flag | Off | Revokes one of your account keys instead. |

### Scopes

| Scope | Allows |
| --- | --- |
| `deploy:write` | Deploying code. |
| `environments:write` | Making environments. |
| `environments:delete` | Deleting environments. |
| `secrets:read` | Listing an environment's secrets by name. Their values are never read back. |
| `secrets:write` | Setting and removing secrets. Includes `secrets:read`. |
| `data:read` | Taking data out: reading tables and files, exports, and the source of a fork. |
| `data:write` | Putting data in: changing tables and files, imports, restores, and the target of a fork. Includes `data:read`. |
| `tenants:write` | Making, deploying to, changing and deleting tenants. |
| `keys:read` | Listing an environment's publishable keys and secret tokens. |
| `keys:write` | Making, changing, rotating and revoking them. Includes `keys:read`. |
| `logs:read` | Reading logs. |
| `traces:read` | Reading traces. |
| `metrics:read` | Reading metrics. |
| `telemetry:read` | Logs, traces and metrics together. |
| `usage:read` | Reading usage and cost. |
| `audit:read` | Reading the organisation's audit log. |
| `tokens:write` | Making, listing, rotating and revoking API tokens. |
| `billing:read` | Reading the plan and what is spent. Only for a token made with `--org`. |
| `projects:write` | Making projects. Only for a token made with `--org`. |
| `projects:delete` | Deleting projects. Only for a token made with `--org`. |

## Good to know

- A token or key is printed once, on standard output. Luna keeps only its hash, so store it before you close the terminal.
- You can give a token only what you can do yourself. A token made by another token stays within that token's scopes and reach, and never outlives it.
- An account key without `--write` only reads. Your login on this machine is an account key too, named `CLI:` and the machine's name, and `luna tokens list --account` shows it.
- Only your login makes account keys. Another account key cannot. An account has at most 50 account keys.
- Set `LUNA_TOKEN` to a token and every command acts with it instead of your login.

:::warning
`revoke` ends a token at once. Every program that sends it is refused from then on. Use `rotate` to move programs over first.
:::

## Examples

### Make a deploy token for CI

```bash
luna tokens create --name ci --scope deploy:write --project acme/notes --env production
```

### Make a token that reads logs for 30 days

```bash
luna tokens create --name dashboard --scope telemetry:read --expires-in 30d
```

### Make a token for a whole organisation

```bash
luna tokens create --name provisioner --org acme --scope projects:write --scope deploy:write
```

### Make an account key that can change things

```bash
luna tokens create --account --write --name laptop-script
```

### Rotate a token with a day of overlap

```bash
luna tokens rotate <TOKEN_ID> --overlap 1d
```

### Revoke an account key

```bash
luna tokens revoke <KEY_ID> --account
```
