# Create an API key

> Page: https://docs.plotwork.dev/api/post-user-api-keys. Index of every page: https://docs.plotwork.dev/llms.txt

Makes a key and returns its full value.

`POST /user/api-keys`

## TL;DR

| Question | Answer |
|---|---|
| What does it do? | Create an API key. |
| What does it take? | A JSON body of type [`CreateApiKeyBody`](https://docs.plotwork.dev/api/schemas.md#createapikeybody). |
| What does it return? | Status 201 with a body of type [`CreatedApiKey`](https://docs.plotwork.dev/api/schemas.md#createdapikey). |
| What can go wrong? | `400` the body is not valid; `401` not signed in; `403` the request came from an origin that may not make changes; `409` the account already holds the most keys allowed; `429` too many requests. Every failure uses the one error envelope. |

## What it does

Makes a key and returns its full value. A sealed copy is kept when the server can, so the key can be revealed again; otherwise this answer is the only time it is shown.

## Request body

The body has the type [`CreateApiKeyBody`](https://docs.plotwork.dev/api/schemas.md#createapikeybody).

| Field | Type | Required | Description |
|---|---|---|---|
| `name` | `string` | yes | at least 1 character; at most 60 characters; pattern `\S`. |

## Responses

| Status | Meaning | Body |
|---|---|---|
| 201 | The new key, including its full value. | [`CreatedApiKey`](https://docs.plotwork.dev/api/schemas.md#createdapikey) |
| 400 | The body is not valid. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 401 | Not signed in. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 403 | The request came from an origin that may not make changes. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 409 | The account already holds the most keys allowed. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 429 | Too many requests. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |

## Response body

A 201 answer has the type [`CreatedApiKey`](https://docs.plotwork.dev/api/schemas.md#createdapikey).

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | `string` | yes |  |
| `name` | `string` | yes |  |
| `prefix` | `string` | yes |  |
| `last4` | `string` | yes |  |
| `createdAt` | `integer` | yes | Milliseconds since the epoch. |
| `lastUsedAt` | `integer \| null` | yes | Milliseconds since the epoch, or null if never used. |
| `revealable` | `boolean` | yes | True when the full key can be shown again with the reveal route. False for a key made before that was possible, or on a server that cannot seal keys. |
| `key` | `string` | yes | The full key. When `revealable` is false this is the only time it is shown, so store it now. |

## See also

| Doc | Why |
|---|---|
| [API reference](https://docs.plotwork.dev/api/reference.md) | Every endpoint, and the error envelope |
| [Schemas](https://docs.plotwork.dev/api/schemas.md) | Every request and response type |
| [Tool reference](https://docs.plotwork.dev/mcp/tools.md) | The operations as callable tools |
