# Create a key

Makes an API key and shows it once.

`POST /v1/keys` on `https://api.eu.vatis.tech`

> **Admin key only.** A Member key gets `403` `admin_only`. Roles: [Authentication and API keys](https://platform.vatis.tech/docs/authentication).

## Headers

| header | values | default | meaning |
|---|---|---|---|
| `Authorization` | `Bearer <api key>` | required | An Admin key ([Roles](https://platform.vatis.tech/docs/authentication#roles)). A Member key gets `403` `admin_only`. |

## Body fields (`application/json`)

| field | values | default | meaning |
|---|---|---|---|
| `name` | 1 to 64 letters, digits, dots, dashes or underscores | required | One per application. No two active keys of a workspace share a name. |
| `role` | `admin`, `member` | `member` | What the key may do ([Roles](https://platform.vatis.tech/docs/authentication#roles)). |
| `expires_on` | `YYYY-MM-DD`, or `null` |  | The last UTC day the key works. Without it, the key has no end. |

## Response fields

| field | when | meaning |
|---|---|---|
| `id` |  | `key_` and 12 hex digits. |
| `name` |  | The key's name. |
| `prefix` |  | The key's first characters, to tell it apart. |
| `role` |  | `admin` or `member` ([Roles](https://platform.vatis.tech/docs/authentication#roles)). |
| `state` |  | `active`, `expired` or `revoked`. |
| `created_at` |  | When it was made: ISO 8601, UTC. |
| `last_used_at` |  | When it last made a request, or `null`: never used. |
| `expires_at` |  | When it stops: the start of the day after its last day, in UTC. `null`: no end. |
| `revoked_at` |  | When it was revoked, or `null`. |
| `key` | only in this answer | `vatis_sk_...`: the key. Hand it to its application through a channel you trust. |

## Responses

`201`: The key, shown only here. The answer has `Cache-Control: no-store`.

```json
{
  "id": "key_3f9c1a2b7d4e",
  "name": "crm-backend",
  "prefix": "vatis_sk_AbCdEf",
  "role": "member",
  "state": "active",
  "created_at": "2026-11-12T09:14:03Z",
  "last_used_at": null,
  "expires_at": null,
  "revoked_at": null,
  "key": "vatis_sk_..."
}
```

`400` `missing_parameter`: No `name`.

`400` `invalid_parameter`: A field that is unknown or not valid, a day that has passed, or a query parameter. The `param` names it.

```json
{
  "error": {
    "code": "invalid_parameter",
    "message": "'name' must be 1 to 64 letters, digits, dots, dashes or underscores.",
    "param": "name",
    "request_id": "req_bf2fed760ba5437ba0933a57"
  }
}
```

`400` `invalid_request`: A body that is not a JSON object.

`401` `unauthorized`: No key, or a wrong, revoked or expired one.

```json
{
  "error": {
    "code": "unauthorized",
    "message": "Invalid, revoked or expired key.",
    "param": null,
    "request_id": "req_bf2fed760ba5437ba0933a57"
  }
}
```

`403` `admin_only`: A Member key.

`409` `name_taken`: An active key has that name. Revoke it first, or pick another name.

`413` `request_too_large`: A JSON body over 64 KB.

`503` `unavailable`: The service is busy for a moment. Send the request again after the seconds of the `Retry-After` header.

## Notes

- **A lost key cannot be shown again:** the API keeps only its hash and prefix. Make a new one and revoke the old one.
- A new workspace has no keys: verify your email, then create the first one on the console's [API keys](https://platform.vatis.tech/keys) page ([API keys](https://platform.vatis.tech/docs/authentication#api-keys)).
