# list()

Canonical URL: https://developers.iagenify.com/sdk/ref/keys/list/
Language: en

`api.keys.list() → Promise<{ ok, keys }>`

Every active key on the account, with its name, its prefix and when it was last used. No secret comes back.

Status: GET /api/keys · free · an envelope, not an array

## Returns {#returns}

```javascript
{
  ok: true,
  keys: [
    {
      id: "…",
      name: "ci",
      prefix: "ia_…",
      scopes: ["*"],
      lastUsedAt: "2026-10-07T09:12:44.102Z",
      expiresAt: null,
      isActive: true,
      createdAt: "2026-09-30T18:02:11.000Z"
    }
  ]
}
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | What [revoke()](/sdk/ref/keys/revoke) takes. It appears here and nowhere else. |
| `name` | string |  | The name given when the key was created, in your account. Not unique — two keys may share one. |
| `prefix` | string |  | The short identifier. This is how you match a stored key to a row here. |
| `scopes` | string[] |  | The label recorded with the key. `["*"]` when none was given. |
| `lastUsedAt` | string|null |  | Updated whenever the key is used. `null` means it never has been. |
| `expiresAt` | string|null |  | An expiry, when the key carries one. `null` otherwise. |
| `isActive` | boolean |  | Revoking sets this to false. |
| `createdAt` | string |  | When it was made. Newest first. |

Dates are ISO strings, so `Date.parse` reads them and a plain string comparison sorts them. Revoked keys are not returned: the lookup is scoped to the account's active keys.

## Which row is the key I am holding {#identify}

Never by comparing the key itself — the list has no secret to compare against. Store the prefix next to the key when you deploy it, and matching is exact and harmless.

```javascript
const { keys } = await api.keys.list();

const mine = keys.find((k) => k.prefix === process.env.IAGENIFY_KEY_PREFIX);

if (!mine) {
  // The key this process holds is not an active key on the account any more.
  throw new Error("this deployment is running on a revoked or unknown key");
}
```

## The audit this gives you {#audit}

`lastUsedAt` is the only field here that tells you something you did not already know. Two questions are worth asking of it.

### What is not being used

```javascript
const { keys } = await api.keys.list();
const month = Date.now() - 30 * 24 * 60 * 60 * 1000;

const idle = keys.filter((k) => !k.lastUsedAt || Date.parse(k.lastUsedAt) < month);

for (const k of idle) {
  console.warn(`${k.name} (${k.prefix}) · last used ${k.lastUsedAt ?? "never"}`);
}
```

A key nothing uses is a key that can be revoked, and every one you retire is one less thing to leak. A key that has *never* been used is usually a rotation that was created and never deployed.

### What is being used when it should not be

```javascript
// A key belonging to a deployment you have retired should go quiet.
// If it does not, something still holds it.
const retired = keys.find((k) => k.name === "old-batch-runner");

if (retired?.lastUsedAt && Date.parse(retired.lastUsedAt) > Date.parse(retiredOn)) {
  // Something is still calling with it. Revoke it and find out what breaks.
}
```

> **lastUsedAt is a time, not a trail**
>
> It tells you a key was used and when it was last used. It does not say from where, or for what. Treat it as a tripwire worth checking, and name your keys well enough that the answer is obvious.

## A readable inventory {#inventory}

```javascript
const { keys } = await api.keys.list();

const rows = keys.map((k) => ({
  name: k.name,
  prefix: k.prefix,
  age: Math.round((Date.now() - Date.parse(k.createdAt)) / 86_400_000) + "d",
  used: k.lastUsedAt
    ? Math.round((Date.now() - Date.parse(k.lastUsedAt)) / 86_400_000) + "d ago"
    : "never",
}));

console.table(rows);
```

- [revoke()](/sdk/ref/keys/revoke): Using an id from this list.
- [api.keys](/sdk/ref/keys): Rotation, and where to keep a key.

```python
{
    "ok": True,
    "keys": [
        {
            "id": "…",
            "name": "ci",
            "prefix": "ia_…",
            "scopes": ["*"],
            "lastUsedAt": "2026-10-07T09:12:44.102Z",
            "expiresAt": None,
            "isActive": True,
            "createdAt": "2026-09-30T18:02:11.000Z",
        }
    ],
}
```

```python
import os

keys = api.keys.list()["keys"]

mine = next((k for k in keys if k["prefix"] == os.environ["IAGENIFY_KEY_PREFIX"]), None)

if mine is None:
    # The key this process holds is not an active key on the account any more.
    raise RuntimeError("this deployment is running on a revoked or unknown key")
```

```python
from datetime import datetime, timedelta, timezone

keys = api.keys.list()["keys"]
month = datetime.now(timezone.utc) - timedelta(days=30)

def when(value): return datetime.fromisoformat(value.replace("Z", "+00:00"))

idle = [k for k in keys if not k.get("lastUsedAt") or when(k["lastUsedAt"]) < month]

for k in idle:
    print(f"{k['name']} ({k['prefix']}) · last used {k.get('lastUsedAt') or 'never'}")
```

```python
# A key belonging to a deployment you have retired should go quiet.
# If it does not, something still holds it.
retired = next((k for k in keys if k["name"] == "old-batch-runner"), None)

if retired and retired.get("lastUsedAt") and when(retired["lastUsedAt"]) > when(retired_on):
    pass  # Something is still calling with it. Revoke it and find out what breaks.
```

```python
from datetime import datetime, timezone

keys = api.keys.list()["keys"]
now = datetime.now(timezone.utc)

def days_since(value): return (now - datetime.fromisoformat(value.replace("Z", "+00:00"))).days

for k in keys:
    used = f"{days_since(k['lastUsedAt'])}d ago" if k.get("lastUsedAt") else "never"
    print(f"{k['name']:<20} {k['prefix']:<12} {days_since(k['createdAt'])}d  {used}")
```
