## API keys (`api-keys`)

API keys of the current user. The plaintext key is returned only once at creation, and scopes can be limited per domain.

Authentication: User · Docs: https://www-demo.kuxitong.com/en/docs/api/api-keys

### GET `/api/v2/api-keys`

List API keys · Authentication: User

Query parameters:

| Field | Type | Required | Description |
|---|---|---|---|
| `page` | integer |  | Page number, starting from 1 Default: 1 |
| `page_size` | integer |  | Items per page Default: 20 |
| `sort` | string |  | Sort fields, comma-separated; prefix `-` for descending, e.g. `-created_at,id` |

```sh
curl "https://panel.example.com/api/v2/api-keys" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### POST `/api/v2/api-keys`

Create API key · Authentication: User

Request body:

| Field | Type | Required | Description |
|---|---|---|---|
| `allow_ips` | ApiKeyAllowIps |  | Caller IP allowlist (single IPs only, at most 200); empty means no restriction. Calls from other IPs get 401 as invalid credentials |
| `expires_at` | string |  | Expires at |
| `name` | string | Yes | Name |
| `scopes` | string[] | Yes | Granted scopes, same values as scopes at creation |

```sh
curl -X POST "https://panel.example.com/api/v2/api-keys" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### PUT `/api/v2/api-keys/{id}`

Update API key IP allowlist or reset it · Authentication: User

Request body:

| Field | Type | Required | Description |
|---|---|---|---|
| `allow_ips` | ApiKeyAllowIps |  | Caller IP allowlist (single IPs only, at most 200); empty means no restriction. Calls from other IPs get 401 as invalid credentials |
| `reset` | boolean |  | When true, issue a new key; the old one stops working at once |

```sh
curl -X PUT "https://panel.example.com/api/v2/api-keys/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"reset":true}'
```

### DELETE `/api/v2/api-keys/{id}`

Delete API key · Authentication: User

```sh
curl -X DELETE "https://panel.example.com/api/v2/api-keys/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

API keys object:

| Field | Type | Required | Description |
|---|---|---|---|
| `allow_ips` | ApiKeyAllowIps |  | Caller IP allowlist (single IPs only, at most 200); empty means no restriction. Calls from other IPs get 401 as invalid credentials |
| `created_at` | string |  | Created at (read-only) |
| `expires_at` | string |  | Expires at |
| `id` | integer |  | Record ID (read-only) |
| `last_used_at` | string |  | Time of last use; null if never used |
| `name` | string |  | Name |
| `prefix` | string |  | First few characters of the plaintext key, for recognition |
| `reset` | boolean |  | When true, issue a new key; the old one stops working at once |
| `scopes` | string[] |  | Granted scopes, same values as scopes at creation |
| `secret` | string |  | Plaintext key (the X-API-Key value), returned only once at creation; only a hash is stored |
| `updated_at` | string |  | Updated at (read-only) |
