Returns
{ ok: true }{"ok": True}What goes
| 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 |
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 catchassistant.destroy()
assistant.destroy() # {"ok": True} again — nothing to catchThe 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()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.