---
title: "Create an API key for the calling key's user."
method: POST
path: "/api/api-keys"
tags: ["API Keys"]
---

# Create an API key for the calling key's user.

`POST /api/api-keys`

## Request

- Base URL: `/` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/api-keys`
- Auth: HTTP bearer

Mints a key for the calling key's user, so a key can be rotated without an administrator. The scopes must be a subset of those the calling key holds. The key is returned once: only its hash is stored. Recorded as an api_key_created audit event naming the calling user and API key. Requires the `api-keys:write` scope.

## Headers

- `Authorization` string, required

## Request body

- CreateApiKeyRequest
  - `scopes` string[]

## Response `201`

The key was created. The value is returned here and nowhere else.

- CreatedApiKeyResponse
  - `apiKey` string
  - `id` string
  - `scopes` string[]
  - `username` string

## Other responses

- `400`: No scopes were given, or one of them is not a scope.
- `401`: The Authorization header is absent or the API key is not recognized.
- `403`: The key does not hold api-keys:write, is a session key, or a requested scope is not held by the calling key.
- `404`: Not Found
- `406`: No representation matches Accept.
- `413`: Content Too Large
- `415`: Unsupported Media Type
- `500`: Internal Server Error
- `503`: Service Unavailable

## Changes

- **2026-10-10** `c4f85daa9208`: 15 info
  - added the non-success response with the status `404`
  - added the optional property `field` to the response with the `400` status
  - added the optional property `field` to the response with the `401` status
  - added the optional property `field` to the response with the `403` status
  - …11 more
- **2026-10-05** `4082c17721d8`: 6 breaking, 6 info
  - removed the media type `*/*` for the response with the status `400`
  - removed the media type `*/*` for the response with the status `401`
  - removed the media type `*/*` for the response with the status `413`
  - removed the media type `*/*` for the response with the status `415`
  - …8 more
- **2026-10-05** `89b2d9d7eb05`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/philterd/apis/philter-api/changes/api/api-keys/post.md)

---

[API](https://skmtc.dev/philterd/apis/philter-api.md) - [All operations](https://skmtc.dev/philterd/apis/philter-api/llms.txt) - [OpenAPI document](https://skmtc.dev/philterd/apis/philter-api/revisions/aa3d7ad1aab4?raw)
