# API keys API

The API keys API: make personal API keys, cut child keys and turn them off, with every endpoint's fields, who may call it, its rate limit and a curl example.

## Make a personal API key (`hmk_…`) for your own scripts, bots and the SDK, holding only the scopes you choose: the same ones apps ask for, and `keys:write` for a key that cuts child keys from itself. The response is the only time its token is shown: hematite keeps just a keyed hash of its secret. It works until `expiresAt`, in the future and at most 366 days away, or 90 days when left out. An account has at most 10 API keys, each with at most 10 child keys. Only a person signed in to hematite makes one: no API key, app or upload token can. With two-step sign-in on, it asks for a fresh step-up first (401 `REAUTH_REQUIRED`, `POST /auth/reauth`).

`POST /keys`

Needs a session token. Rate limit: 10 a minute, per address. Not open to apps or API keys: API keys are made, listed and turned off by their user, signed in to hematite.

### Body

| Field | Type | Required | Notes |
|---|---|---|---|
| `note` | `string` | required | Its name, 1 to 40 characters: what it's for, as Settings → API keys lists it. 1 to 40 characters. |
| `scopes` | `enum[]` | required | What it may do: at least one scope, each once. At least 1 items. |
| `expiresAt` | `date-time` |  |  |
| `constraints` | `object` |  | What narrows it further. Left out, it works from anywhere, as often as the api's limits allow, until it expires. |
| `constraints.ips` | `string[]` |  | Where it works from: up to 16 single addresses or CIDR ranges, IPv4 or IPv6. A request from anywhere else is refused as if the key were wrong. 1 to 16 items. |
| `constraints.perMinute` | `integer` |  | At most this many requests a minute, across every endpoint, 1 to 120; a 429 past it. 1 to 120. |
| `constraints.usesLeft` | `integer` |  | How many requests it makes before it ends by itself, each request one. 1 to 1000000. |
| `constraints.folderId` | `number \| null` |  | A folder of yours: every image the key uploads goes into it, whatever the upload says. Needs `images:write`; null for none. |
| `constraints.visibility` | `enum` |  | Every image the key uploads gets this visibility, whatever the upload says. Needs `images:write`. One of `Unlisted`, `Public`, `Private`. |

### Response

Returns an [ApiKey](https://hematite.gg/docs/developers/models/api-key), plus this field:

| Field | Type | Present | Notes |
|---|---|---|---|
| `token` | `string` |  | The key (`hmk_…`), shown only now: hematite keeps just a keyed hash of its secret. |

Error `403`.

Error `409`.

```bash
curl -X POST 'https://api.hematite.gg/v1/keys' \
  -H "Authorization: $HEMATITE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"note":"ShareX","scopes":["images:read"]}'
```

Example `data`:

```json
{
  "publicId": "m0plGGtn67kMZy6D",
  "note": "ShareX",
  "scopes": [
    "images:read"
  ],
  "constraints": {
    "ips": [
      "203.0.113.7"
    ],
    "perMinute": 0,
    "folderId": 1,
    "visibility": "Unlisted"
  },
  "usesLeft": 0,
  "parent": "string",
  "createdAt": "2026-11-10T18:24:00.000Z",
  "usedAt": "2026-11-10T18:24:00.000Z",
  "expiresAt": "2026-11-10T18:24:00.000Z",
  "token": "hms_live_m0plGGtn67kMZy6D_…"
}
```

## Turn an API key off: it stops working at once, and every child key cut from it with it. Signed in, any of your keys; an API key with `keys:write`, only the children it cut. Never asks for your password again: stopping access is always one request.

`DELETE /keys/:publicId`

Needs a session token. Rate limit: 120 a minute, per address. Not open to apps: API keys are made, listed and turned off by their user, signed in to hematite. An API key with `keys:write` may, for its own child keys.

### Path parameters

| Field | Type | Required | Notes |
|---|---|---|---|
| `publicId` | `string` | required |  |

### Response

`data` is empty.

Error `403`.

Error `404`: No API key of yours with this public id works.

```bash
curl -X DELETE 'https://api.hematite.gg/v1/keys/m0plGGtn67kMZy6D' \
  -H "Authorization: $HEMATITE_TOKEN"
```

## Cut a child key from an API key (concept 22 §7.2): never wider than its parent. Its scopes are among the parent's (`keys:write` never: children are one level deep), it ends no later, works from the parent's addresses or fewer, has no more uses than the parent has left (and each of its uses is the parent's too), no higher a rate, and uploads where the parent uploads; what it doesn't name it takes from the parent. It ends when its parent does. Signed in, from any of your keys, with a fresh step-up for a child that writes when two-step sign-in is on (401 `REAUTH_REQUIRED`); an API key with `keys:write`, from itself only. A field that would make it wider answers 400 with that field's issue. At most 10 children a key. The response is the only time its token is shown.

`POST /keys/:publicId/children`

Needs a session token. Rate limit: 30 a minute, per address. Not open to apps: API keys are made, listed and turned off by their user, signed in to hematite. An API key with `keys:write` may, for its own child keys.

### Path parameters

| Field | Type | Required | Notes |
|---|---|---|---|
| `publicId` | `string` | required |  |

### Body

| Field | Type | Required | Notes |
|---|---|---|---|
| `note` | `string` | required | Its name, 1 to 40 characters: what it's for, as Settings → API keys lists it. 1 to 40 characters. |
| `scopes` | `enum[]` | required | What it may do: at least one scope, each once. At least 1 items. |
| `expiresAt` | `date-time` |  |  |
| `constraints` | `object` |  | What narrows it further. Left out, it works from anywhere, as often as the api's limits allow, until it expires. |
| `constraints.ips` | `string[]` |  | Where it works from: up to 16 single addresses or CIDR ranges, IPv4 or IPv6. A request from anywhere else is refused as if the key were wrong. 1 to 16 items. |
| `constraints.perMinute` | `integer` |  | At most this many requests a minute, across every endpoint, 1 to 120; a 429 past it. 1 to 120. |
| `constraints.usesLeft` | `integer` |  | How many requests it makes before it ends by itself, each request one. 1 to 1000000. |
| `constraints.folderId` | `number \| null` |  | A folder of yours: every image the key uploads goes into it, whatever the upload says. Needs `images:write`; null for none. |
| `constraints.visibility` | `enum` |  | Every image the key uploads gets this visibility, whatever the upload says. Needs `images:write`. One of `Unlisted`, `Public`, `Private`. |

### Response

Returns an [ApiKey](https://hematite.gg/docs/developers/models/api-key), plus this field:

| Field | Type | Present | Notes |
|---|---|---|---|
| `token` | `string` |  | The key (`hmk_…`), shown only now: hematite keeps just a keyed hash of its secret. |

Error `400`.

Error `403`.

Error `404`: No API key of yours with this public id works.

Error `409`.

```bash
curl -X POST 'https://api.hematite.gg/v1/keys/m0plGGtn67kMZy6D/children' \
  -H "Authorization: $HEMATITE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"note":"ShareX","scopes":["images:read"]}'
```

Example `data`:

```json
{
  "publicId": "m0plGGtn67kMZy6D",
  "note": "ShareX",
  "scopes": [
    "images:read"
  ],
  "constraints": {
    "ips": [
      "203.0.113.7"
    ],
    "perMinute": 0,
    "folderId": 1,
    "visibility": "Unlisted"
  },
  "usesLeft": 0,
  "parent": "string",
  "createdAt": "2026-11-10T18:24:00.000Z",
  "usedAt": "2026-11-10T18:24:00.000Z",
  "expiresAt": "2026-11-10T18:24:00.000Z",
  "token": "hms_live_m0plGGtn67kMZy6D_…"
}
```
