# list()

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

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

Ogni chiave attiva del conto, con il nome, prefixe e quando fu usata.

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

## Retorno {#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 |  | Qua [revoke()](/pt/sdk/ref/keys/revoke)prende. Aparece qui e nùcun altro. |
| `name` | string |  | Il nome dato quando la chiave è stata creata, in tuo conto. Non unico — due chiues possono dividere una. |
| `prefix` | string |  | Identificatori corto. Itèra la forma in cui si combina una tecla memorizzata a una fila. |
| `scopes` | string[] |  | L'etiqueta registrata con la tecla. `["*"]` quando non era dada. |
| `lastUsedAt` | string|null |  | Actualized ogni volta che la chiave è usat. `null` significa che nunca ha fost. |
| `expiresAt` | string|null |  | Una caduca, quando la tecla porta uno. `null` altrimenti. |
| `isActive` | boolean |  | Revoking sets esto a false. |
| `createdAt` | string |  | Quando fu creata, prima la prima novella. |

Le dates sono ISO stringhes, quindi `Date.parse` le lège e una comparazion di stringhes simples trie. Chiaves revocate non sono restituites: la consulta è delimitata a chaves actives del conto.

## Quale fila è la chave che tengo {#identify}

Mai comparando la chiave in sé — la lista non ha alcun segreto contra contra. Met a tasto il prefix al titulo quando lo implora, e la corrispondenza è exacta e inofensiv.

```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");
}
```

## L'audito di questo ti da {#audit}

`lastUsedAt` è l'unico campo qui vi dice qualcosa che non sapevi.

### Ce non è usat

```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"}`);
}
```

Una chiave che non usa è una chiave che può essere revocata, e ogni che si retira è una cosa meno a filtrare. Una chiave che ha *nunca* è usata è generalmente una rotazione che è creata e mai implementata.

### Ce è usat quando non deve ser

```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 è un tempo, non un sentiero**
>
> Te dice una chiave è stato usat e quando è stato usat ultima. Non dice da da da où, o per què. Trattalo come un tripwire vale la pena check, e nomeare le chiavi abbastanza bene che la risposta è obvia.

## Un inventari legìbile {#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()](/pt/sdk/ref/keys/revoke): Usando un identitât de esta lista.
- [api.keys](/pt/sdk/ref/keys): Rotazione, e onde gardî una chiave.

```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}")
```
