---
title: luna keys
description: List, make, rotate and revoke the publishable keys and secret tokens that call an environment's lunas.
related:
  - /concepts/keys-and-tokens
  - /clients/call-lunas-over-http
  - /cli/tokens
---

`luna keys` manages the credentials your app calls an environment's lunas with: publishable keys and secret tokens.

```bash
luna keys list
```

## Reference

```bash
luna keys <COMMAND>
```

Every subcommand acts on one environment, and takes these options.

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `--dir <DIR>` | path | `.` | The app's folder. Its env file names the project and environment. |
| `--env <ENV>` | text | `LUNA_ENV`, then `production` | The environment, by name. |
| `--project <PROJECT>` | text | `LUNA_PROJECT` | The project, by name or as `organisation/project`. |
| `--tenant <TENANT>` | text | The environment's own | A tenant added to the environment, by name. |
| `--token <TOKEN>` | text | `LUNA_TOKEN`, then your login | An API token or account key to act with. |

### luna keys list

Prints the environment's keys: each one's id, kind, name and, for a publishable key, the key itself.

```bash
luna keys list [OPTIONS]
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `--json` | flag | Off | Prints the answer as JSON, with each key's origins, rate, types and expiry. |

### luna keys create

Makes a publishable key, or a secret token with `--secret`, and prints it.

```bash
luna keys create [OPTIONS]
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `--secret` | flag | Off | Makes a secret token instead of a publishable key. |
| `--name <NAME>` | text | Empty | A name to tell it by. |
| `--origin <ORIGIN>` | text, repeatable | Any origin | An origin a browser may use it from, such as `https://app.example.com`. |
| `--rate <RATE>` | number | No limit of its own | The most requests a second it may make. More than 0. |
| `--type <TYPE>` | text, repeatable | Every type | A luna type it may call. |
| `--expires-in <EXPIRES_IN>` | duration | Never | It stops working after this long, such as `90m` or `30d`, or a number of seconds. |

### luna keys rotate

Makes a replacement for a key or token, and prints it with its id. A main key keeps its id. An added key's replacement gets a new id, which `revoke` and the next `rotate` take. The old one goes on working for the overlap.

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

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

### luna keys revoke

Stops a key or token working at once, for open connections too.

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

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `<ID>` | text | Required | The key's id, from `luna keys list`. |

## Good to know

- Every environment starts with one publishable key and one secret token. Their ids are `primary` and `primary-secret`.
- A publishable key starts with `pk_` and is safe to ship in an app. A secret token starts with `sk_` and is printed only once, so store it before you close the terminal.
- The two main credentials cannot be revoked. Rotate them instead, with `--overlap 0` to end the old one at once.
- An environment can have at most 100 keys.
- `list` needs the `keys:read` scope. `create`, `rotate` and `revoke` need `keys:write`.

:::warning
`revoke` and a rotation with `--overlap 0` end the old credential at once. Every app that still sends it is refused.
:::

## Examples

### Make a publishable key for one website

```bash
luna keys create --name web --origin https://app.example.com --rate 50
```

### Make a secret token that calls one luna type

```bash
luna keys create --secret --name worker --type List
```

### Make a key for staging that expires

```bash
luna keys create --env staging --name preview --expires-in 7d
```

### Rotate the main secret token

```bash
luna keys rotate primary-secret --overlap 2h
```

### Revoke a key

```bash
luna keys revoke <KEY_ID>
```
