AssistantSession

destroy()

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

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

DELETE /api/ai/models/:idfreenot reversible
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Returns

{ ok: true }
{"ok": True}

What goes

After destroy()
The sessiongone — get(id) answers 404
Its messagesgone with it
Files it generateduntouched, wherever you wrote them
Credits it spentunchanged — 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.

const { messages } = await assistant.getHistory();
await archive.put(assistant.id, { session: assistant.data, messages });
await assistant.destroy();
messages = assistant.get_history()["messages"]
archive.put(assistant.id, {"session": assistant.data, "messages": messages})
assistant.destroy()

Deleting twice is not an error

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.

await assistant.destroy();
await assistant.destroy();   // { ok: true } again — nothing to catch
assistant.destroy()
assistant.destroy()   # {"ok": True} again — nothing to catch

The object afterwards

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

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.

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();
}
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()
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.