# idpc keys

Inspect and manage API keys.

Every subcommand accepts `[key]` as an optional first positional. If omitted, the resolved api\_key is used, so `idpc keys details` and `idpc keys details ak_xxx` behave the same when your own key is configured.

All subcommands except `keys get`, `keys context` and `keys configs get` **require a user\_token**. The CLI preflights this before any HTTP call: if no user\_token is found via `--user-token`, `IDPC_USER_TOKEN` or `idpc auth login`, the command exits with `code: missing_user_token` and a hint pointing to those three sources.

## `idpc keys get [key]`

Public availability info: `GET /keys/{key}`. No user\_token is attached (the response shape changes if one is present, so the CLI explicitly omits it even when available). The response reports `available`; geographic context lives under `keys context`.

## `idpc keys context [key]`

Geographic context for a key: `GET /keys/{key}`. Reports `context` (the likely context for the requesting agent) and `contexts` (every context available to the key). No user\_token is attached.

## `idpc keys details [key]`

Private key details: `GET /keys/{key}/details`. **Requires user\_token.** Reports name, limits, allowed URLs, notifications and purchases. Dataset availability lives under `keys datasets`; available contexts under `keys context`.

## `idpc keys datasets [key]`

Dataset availability for a key: `GET /keys/{key}/details`. **Requires user\_token.** Reports the `datasets` map (each dataset → boolean).

### `update [key]`

Enable or disable datasets: `PUT /keys/{key}/details`. **Requires user\_token.** Returns the updated `datasets` map.

| Flag                      | Description                     |
| ------------------------- | ------------------------------- |
| `-e, --enable <dataset>`  | Dataset to enable. Repeatable.  |
| `-d, --disable <dataset>` | Dataset to disable. Repeatable. |

At least one `--enable` or `--disable` is required. A dataset passed to both is rejected with `code: invalid_input`.

```bash
idpc keys datasets update -e paf -e abp -d mr
```

## `idpc keys update [key]`

Update key details: `PUT /keys/{key}/details`. **Requires user\_token.**

| Flag                 | Description                                      |
| -------------------- | ------------------------------------------------ |
| `--json-body <json>` | **Required.** Raw JSON body of fields to update. |

```bash
idpc keys update --json-body '{"notifications":{"email":"ops@example.com"}}'
```

## `idpc keys usage [key]`

Lookup counts over a date range: `GET /keys/{key}/usage`. **Requires user\_token.**

| Flag              | Description                    |
| ----------------- | ------------------------------ |
| `--start <date>`  | Start date (YYYY-MM-DD or ISO) |
| `--end <date>`    | End date                       |
| `--tags <csv>`    | Comma-separated tag filter     |
| `--licensee <id>` | Filter by licensee id          |

## `idpc keys logs [key]`

Paid lookup logs: `GET /keys/{key}/lookups`. Emits **raw CSV to stdout**. **Requires user\_token.**

| Flag              | Description           |
| ----------------- | --------------------- |
| `--start <date>`  | Start date            |
| `--end <date>`    | End date              |
| `--licensee <id>` | Filter by licensee id |

This command is CSV-only and does not support `--json` / `-q`; passing either errors with `invalid_input`. Redirect to a file or pipe into CSV tooling:

```bash
idpc keys logs --start 2026-01-01 --end 2026-01-31 > lookups.csv
```

## `idpc keys configs`

All subcommands except `get` **require user\_token**. `get` needs only the API key.

A config's `payload` is an opaque serialised-JSON **string** (matching the API's `ConfigNewParam` / `ConfigUpdateParam`). The CLI validates that it parses as JSON but does not interpret its contents.

### `list [key]`

`GET /keys/{key}/configs`: list all configs.

### `get <config> [key]`

`GET /keys/{key}/configs/{config}`: retrieve one.

### `create <name> [key]`

`POST /keys/{key}/configs`: create a new config.

| Flag               | Description                                            |
| ------------------ | ------------------------------------------------------ |
| `--payload <json>` | **Required.** Serialised config payload (JSON string). |

```bash
idpc keys configs create my-site --payload '{"allowedUrls":["https://example.com"]}'
```

### `update <config> [key]`

`POST /keys/{key}/configs/{config}`: update in place.

| Flag               | Description                                                                           |
| ------------------ | ------------------------------------------------------------------------------------- |
| `--payload <json>` | **Required.** Serialised config payload (JSON string). Replaces the existing payload. |

### `delete <config> [key]`

`DELETE /keys/{key}/configs/{config}`. Requires `--yes` in non-TTY (or `--json`).

| Flag        | Description       |
| ----------- | ----------------- |
| `-y, --yes` | Skip confirmation |
