# destroy()

Canonical URL: https://developers.iagenify.com/sdk/ref/assistant-session/destroy/
Language: en

`assistant.destroy() → Promise<{ ok: true }>`

Deletes the session and every message in it. There is no undo, and no trash.

Status: DELETE /api/ai/models/:id · free · not reversible

## Returns {#returns}

```javascript
{ ok: true }
```

## What goes {#what}

|  | After destroy() |
| --- | --- |
| The session | gone — get(id) answers 404 |
| Its messages | gone with it |
| Files it generated | untouched, wherever you wrote them |
| Credits it spent | unchanged — this is not a refund |

> **Read before you delete**
>
> The conversation is not recoverable. If it was worth anything, getHistory() and write it out first — that call is free.

```javascript
const { messages } = await assistant.getHistory();
await archive.put(assistant.id, { session: assistant.data, messages });
await assistant.destroy();
```

## Deleting twice is not an error {#idempotent}

It answers `{ ok: true }` whether or not there was anything to delete — including for an id that was never valid. So a cleanup job can run twice without special handling, and a success tells you the session is gone, not that it was there.

```javascript
await assistant.destroy();
await assistant.destroy();   // { ok: true } again — nothing to catch
```

## The object afterwards {#after}

The handle still exists in your process and still carries the configuration — the conversation behind it is what is gone. Calling `generate()` on it answers `404 discussion_not_found`. Drop the reference.

## Tidying a lot of them {#cleanup}

Sessions do not expire. A tidy-up is worth having, and it is worth being narrow: delete what was never used, and what belongs to something that no longer exists.

```javascript
const sessions = await api.models.list({ limit: 100 });
const month = Date.now() - 30 * 24 * 60 * 60 * 1000;

for (const s of sessions) {
  const stale = !s.title && Date.parse(s.updatedAt) < month;   // opened, never used, old
  if (!stale) continue;
  await (await api.models.get(s.id)).destroy();
}
```

> **An empty title is the safest signal**
>
> A session is named by its first message, so no title means nothing was ever asked of it. Deleting on age alone would take conversations someone is still using.

- [getHistory()](/sdk/ref/assistant-session/get-history): Reading it out before it goes.
- [api.models.list()](/sdk/ref/models/list): Finding what exists to be tidied.

```python
{"ok": True}
```

```python
messages = assistant.get_history()["messages"]
archive.put(assistant.id, {"session": assistant.data, "messages": messages})
assistant.destroy()
```

```python
assistant.destroy()
assistant.destroy()   # {"ok": True} again — nothing to catch
```

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

sessions = api.models.list(limit=100)
month = datetime.now(timezone.utc) - timedelta(days=30)

for s in sessions:
    updated = datetime.fromisoformat(s["updatedAt"].replace("Z", "+00:00"))
    stale = not s["title"] and updated < month   # opened, never used, old
    if stale:
        api.models.get(s["id"]).destroy()
```
