# Create an organisation API key

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

Makes a key that belongs to the organisation and returns its full value.

`POST /orgs/{org}/keys`

## TL;DR

| Question | Answer |
|---|---|
| What does it do? | Create an organisation API key. |
| What does it take? | A JSON body of type [`CreateOrgApiKeyBody`](https://docs.plotwork.dev/api/schemas.md#createorgapikeybody). |
| What does it return? | Status 201 with a body of type [`CreatedOrgApiKey`](https://docs.plotwork.dev/api/schemas.md#createdorgapikey). |
| What can go wrong? | `400` the body is not valid; `401` not signed in; `403` a member may not make keys (orgs.forbidden), or the request came from an origin that may not make changes; `404` no such organisation, or the caller is not a member of it; `409` the organisation already holds the most keys allowed; `429` too many requests; `503` organisations are not set up on this server. Every failure uses the one error envelope. |

## What it does

Makes a key that belongs to the organisation and returns its full value. It acts only in this organisation, as its scopes allow (`diagrams` by default, `audit:read` for the audit log), and spends the owner's daily allowance. 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. At most ten active keys.

## Path parameters

| Field | Type | Required | Description |
|---|---|---|---|
| `org` | `string` | yes | The organisation's id or its slug. |

## Request body

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

| Field | Type | Required | Description |
|---|---|---|---|
| `name` | `string` | yes | at least 1 character; at most 60 characters; pattern `\S`. |
| `scopes` | `("diagrams" \| "audit:read")[]` | no | What the key may do. Left out, `["diagrams"]`. A key for a SIEM takes `["audit:read"]` alone. |

## Responses

| Status | Meaning | Body |
|---|---|---|
| 201 | The new key, including its full value. | [`CreatedOrgApiKey`](https://docs.plotwork.dev/api/schemas.md#createdorgapikey) |
| 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 | A member may not make keys (orgs.forbidden), or the request came from an origin that may not make changes. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 404 | No such organisation, or the caller is not a member of it. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |
| 409 | The organisation 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) |
| 503 | Organisations are not set up on this server. | [`ErrorResponse`](https://docs.plotwork.dev/api/schemas.md#errorresponse) |

## Response body

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

| 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. |
| `scopes` | `("diagrams" \| "audit:read")[]` | yes | `diagrams`: read the library, publish, and change its diagrams, which every key made before scopes holds. `audit:read`: read and export the audit log, and nothing else unless `diagrams` is also given. |

## 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 |
