# API reference: keys

Scoped API keys for programmatic access (CLI / MCP / SDK)

## GET /v1/keys

`listApiKeys` · scope `session` · List my API keys

Returns metadata only. Key material is never returned after creation. Revoked keys stay listed with `revoked_at` set, so audit history keeps resolving. Newest first. A short-lived child key (`createChildApiKey`) is not listed: it belongs to the key it was made from, lives an hour at most, and the desktop app makes one an hour.

Parameters:

- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of API keys.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).

## POST /v1/keys

`createApiKey` · scope `session` · Create an API key

Mints a scoped programmatic key. The plaintext key (`lucen_sk_...`) is returned **once**, in this response. It is never returned again. Only an argon2 hash is stored. Requested scopes must be a subset of what the caller can grant (`read` ⊂ `write` ⊂ `train`). Lower scopes are implied, so the redundant ones may be omitted. When set, `daily_gpu_hour_quota` caps the GPU hours this key may reserve on priced executors per 24 h. That cap sits inside the account's own `RUN_DAILY_GPU_HOUR_QUOTA` (`createRun`).

Three settings make a key safer to hand to an AI agent. `expires_at` ends the key at that instant. After it the key answers 401 with a problem that says it expired. `limited_to` restricts the key to some repos. Outside them it gets the answer a stranger gets. It may call the repo operations and `getMe`. It may run a robot in its list, under an owner it names whole. It may test in sim a policy on a robot, both in its list. Every other operation answers 403 with `errors[].type` `forbidden.key_limits`. `agent` marks a key an AI agent holds. Its rows in the activity feed say so. Hosted work beyond the free allowance answers 403 `forbidden.agent_key_spend`, because a person starts it.

Request body: `application/json`, required.

Responses:

- `201`: Key created; `key` is the only time the secret is shown.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `422`: Request failed validation.

## POST /v1/keys/child

`createChildApiKey` · scope `key:read` · Mint a short-lived child of this key

Mints a key from the API key that calls, for a program that should not hold the long-lived one. The desktop app gives one to the MCP server it starts. The child has the caller's scopes or fewer, its repo limits and its agent mark. It lives at most one hour (`ttl_s`, 60 to 3600). It stops when its parent is revoked, rotated or expires. A child cannot mint a child, and a session cannot call this: it has no key to derive from. A key with a daily GPU-hour quota cannot mint one either (`403`): the quota is counted per key, and a child would get a budget of its own. The plaintext is returned once. One person has at most five live child keys at a time. A sixth is `429`, with `Retry-After` until the oldest one expires; revoking a child frees its place.

Request body: `application/json`, required.

Responses:

- `201`: Child key created; `key` is the only time the secret is shown.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `422`: Request failed validation.
- `429`: This person already has five live child keys.

## DELETE /v1/keys/{key_id}

`revokeApiKey` · scope `session` · Revoke an API key

Revocation takes effect on the next request and cannot be undone. The row is retained (audit rows point at it). It keeps appearing in `GET /v1/keys` with `revoked_at` set. The short-lived keys made from it (`createChildApiKey`) are revoked with it. Idempotent: revoking an already-revoked key is still 204.

Parameters:

- `key_id` (path, required): API key id (`key_...`).

Responses:

- `204`: Key revoked.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).

## POST /v1/keys/{key_id}/rotate

`rotateApiKey` · scope `session` · Rotate an API key

Mints a new key with the old key's name, scopes, daily GPU-hour cap, repo limits and agent mark. When the old key expires, the new one gets the same lifetime, counted from now. The plaintext is returned once, as `createApiKey` returns it.

The old key keeps working for at most 7 more days, so whatever uses it can switch over. Its `expires_at` becomes the earlier of its own expiry and 7 days from now, and `replaced_by` names the new key. The short-lived keys made from the old key (`createChildApiKey`) are revoked now. Revoking it ends it sooner. A key that is revoked, expired or already rotated answers 409. Someone else's key answers 404.

Parameters:

- `key_id` (path, required): API key id (`key_...`).

Responses:

- `201`: The new key; `key` is the only time its secret is shown.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).

## GET /v1/keys/{key_id}/activity

`listApiKeyActivity` · scope `session` · What one API key did

The activity feed rows written with this key, newest first, with the key itself and a summary of every row it wrote. Each row reads as it does in `listActivity`. The summary counts the actions and names the first and the last. The hub records no IP address, so none is shown. Only the key's owner may read it. Anyone else's key answers 404.

Parameters:

- `key_id` (path, required): API key id (`key_...`).
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: The key, its summary and one page of its rows.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
