---
search:
  tags:
    - API keys
    - POST
seo:
  description: >-
    Makes a key for a program to use, such as a deploy from CI. The key holds
    only the permissions… Reference for the POST /_luna/tokens endpoint in the
    Luna API.
sidebar:
  label: Create an API key
  badge: POST
title: Create an API key
type: openapi-operation
---
Makes a key for a program to use, such as a deploy from CI. The key holds only the permissions you name, and reaches one project, some of its environments or a whole organisation. You can give a key only what you can do yourself, and a key made by another key never outlives it. The key is shown once, in this response.

`POST /_luna/tokens`

**Request body** (`application/json`, required)

- `name` (string) — A name to tell the key by.
- `scopes` (string[], required) — The permissions the key holds, such as \`deploy:write\`. At least one.
- `tenants` (string[]) — The tenants the key reaches, by full name. Naming an environment's default tenant also reaches the tenants added to that environment. Leave empty for all of them.
- `project` (string | null) — The project the key belongs to, as \`organisation/project\`.
- `org` (string | null) — An organisation, by its slug, for a key that reaches every project in it. Give this or \`project\`, not both.
- `environments` (string[]) — The environments the key reaches, by name. Leave empty for all of the project's environments.
- `expiresIn` (integer<int64> | null) — How long the key works, in seconds from now. A key with no lifetime does not expire.

Request body example:

```json
{
  "name": "string",
  "scopes": [
    "string"
  ],
  "tenants": [
    "string"
  ],
  "project": "string",
  "org": "string",
  "environments": [
    "string"
  ],
  "expiresIn": 0
}
```

**Responses**

- `200` — The new key.
- `default` — The request failed. The status says how and \`error.message\` says why.

Response example, 200:

```json
{
  "id": "string",
  "token": "string",
  "expiresMs": 0
}
```
