# API reference: api-keys

Keys for programs. The secret is shown once, when the key is created.

[API conventions](../api.md) explains auth, IDs, lists, errors and idempotency. The examples read the API key from `ARVM_API_KEY`.

## Operations

| Operation | Request |
|---|---|
| [Create an API key](#create-an-api-key) | `POST /v1/api-keys` |
| [List API keys](#list-api-keys) | `GET /v1/api-keys` |
| [Revoke an API key](#revoke-an-api-key) | `DELETE /v1/api-keys/{api_key}` |

## Create an API key

`POST /v1/api-keys`

The response is the only time the key's `secret` is shown. Only its hash is stored.

`scope` is `full` unless the request says `read_only`. A read-only key is for a program that
watches and must not act: a dashboard, a cost report, a monitor. It cannot be widened later.
Make a new key instead.

- Operation ID: `createApiKey`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `Idempotency-Key` | header | string | no | A value the client chooses, such as a UUID. For 24 hours after a request succeeded, a request with the same key and the same body returns the first request's response instead of creating again. A request that failed leaves the key free, with one exception: a `createMachine` refused with `no_capacity` returns the same 503 until its `Retry-After` has passed, and is tried again after. The same key with a different body is `idempotency_key_reused` (409). Minimum length: `1`. Maximum length: `255`. |

**Request body**

`application/json`: [APIKeyCreate](schemas.md#apikeycreate)

**Responses**

| Status | Description | Body |
|---|---|---|
| 201 | The key, with its secret. | `application/json`: [APIKeyWithSecret](schemas.md#apikeywithsecret) |

Errors: `400`, `401`, `403`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/api-keys" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{"name": "ci", "expires_in_seconds": 7776000}'
```

Response body, `application/json`:

```json
{
  "id": "key_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "name": "ci",
  "scope": "full",
  "display_prefix": "arvm_7Qm2",
  "created_at": "2026-11-10T20:25:00Z",
  "expires_at": "2027-02-08T20:25:00Z",
  "secret": "arvm_7Qm2vX9pL4kR8sT1wY6zB3nH5jF0aGdE2cU7iO4yN"
}
```

## List API keys

`GET /v1/api-keys`

Newest first. Secrets are not included.

- Operation ID: `listApiKeys`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `limit` | query | integer (int32) | no | The most items to return. Default: `50`. Minimum: `1`. Maximum: `200`. |
| `cursor` | query | string | no | The `next_cursor` of the previous page. Opaque. Maximum length: `512`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | A page of API keys. | `application/json`: [APIKeyList](schemas.md#apikeylist) |

Errors: `400`, `401`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/api-keys" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "data": [
    {
      "id": "key_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "name": "ci",
      "scope": "full",
      "display_prefix": "arvm_7Qm2",
      "created_at": "2026-11-10T20:25:00Z",
      "last_used_at": "2026-11-10T21:14:09Z",
      "expires_at": "2027-02-08T20:25:00Z"
    }
  ],
  "next_cursor": null
}
```

## Revoke an API key

`DELETE /v1/api-keys/{api_key}`

The key stops working at once.

- Operation ID: `deleteApiKey`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `api_key` | path | [APIKeyID](schemas.md#apikeyid) | yes | The API key's ID, not its secret. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 204 | Revoked. |  |

Errors: `400`, `401`, `403`, `404`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X DELETE "https://api.arvm.dev/v1/api-keys/key_01jcz3k8x0e5v9w2r4t6y8a0bq" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```
