# ApiKey model

A personal API key or a child key cut from one, as its owner sees it: its name, scopes, what narrows it, its uses left and when it ends. Never its token: only the response that makes it has that.

## Fields

| Field | Type | Present | Notes |
|---|---|---|---|
| `publicId` | `string` |  | Names the key: safe to show and to say to support, and what its token starts with after `hmk_live_`. It proves nothing. |
| `note` | `string` |  | Its name, as Settings → API keys lists it. |
| `scopes` | `enum[]` |  | What it may do: the apps' scopes, and `keys:write` for cutting child keys from itself. |
| `constraints` | `object` |  |  |
| `constraints.ips` | `string[]` | optional | The only addresses it works from: single addresses and CIDR ranges, IPv4 or IPv6. From anywhere when left out. |
| `constraints.perMinute` | `integer` | optional | At most this many requests a minute, across every endpoint; a 429 past it. |
| `constraints.folderId` | `integer` | optional | Every image it uploads goes into this folder of yours, whatever the upload says. |
| `constraints.visibility` | `enum` | optional | Every image it uploads gets this visibility, whatever the upload says. One of `Unlisted`, `Public`, `Private`. |
| `usesLeft` | `integer \| null` |  | Requests left before it ends by itself, each request one; null for no limit. |
| `parent` | `string \| null` |  | The public id of the key it was cut from, or null. |
| `createdAt` | `date-time` |  |  |
| `usedAt` | `date-time` |  |  |
| `expiresAt` | `date-time \| null` |  |  |

## Returned by

The endpoints whose `data` holds an ApiKey as it is, and where.

- [`GET /users/:userId/keys`](https://hematite.gg/docs/developers/reference/users#get-users-userid-keys), in `data[].children[]`

## Extended by

The endpoints that return an ApiKey with fields of their own, and the fields they add.

- [`POST /keys`](https://hematite.gg/docs/developers/reference/keys#post-keys) adds `token`
- [`POST /keys/:publicId/children`](https://hematite.gg/docs/developers/reference/keys#post-keys-publicid-children) adds `token`
- [`GET /users/:userId/keys`](https://hematite.gg/docs/developers/reference/users#get-users-userid-keys) adds `children` to each

## Example

```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"
}
```
