api.files

delete()

api.files.delete(sourceId) → Promise<Result>

Removes the file, its record, and whatever was indexed from it for semantic search.

DELETE /api/files/:idfreenot reversible
Using Python?

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

Parameters

sourceIdstringrequired

From list(). Missing → the SDK throws.

Returns

{
  ok: true,
  message: "…",
  sourceId: "…",
  removedChunks: 12     // how many indexed fragments went with it
}
{
    "ok": True,
    "message": "…",
    "sourceId": "…",
    "removedChunks": 12,     # how many indexed fragments went with it
}

removedChunks is the useful one: it tells you how much of the semantic index this file was, and 0 means it was never indexed — which is normal for anything that is not a document.

What goes

After delete()
The bytesgone
The recordgone — get() answers 404
Its indexed fragmentsgone, so search stops returning it
The storage's remaining spacegiven back
A local copy you saved with pathuntouched, on your disk
There is no trash

Read it out first if it mattered — reading is free — or keep the local copy that save({ path }) can write for you at the same time.

const file = await api.files.get(sourceId);
await fs.writeFile(`./archive/${file.name}`, file.content);
await api.files.delete(sourceId);
from pathlib import Path

file = api.files.get(source_id)
content = file.content.encode() if isinstance(file.content, str) else file.content
Path("archive", file.name).write_bytes(content)
api.files.delete(source_id)

Errors

CodeStatusWhen
— (thrown locally)—No sourceId passed.
file_not_found404No file of this account with that id — including one already deleted.

So deleting twice answers 404 the second time. When the goal was simply that the file be gone, treat that as success.

import { IaGenifyError } from "iagenify";

async function ensureGone(api, sourceId) {
  try {
    await api.files.delete(sourceId);
    return "deleted";
  } catch (err) {
    if (err instanceof IaGenifyError && err.status === 404) return "already gone";
    throw err;
  }
}
from iagenify import IaGenifyError

def ensure_gone(api, source_id):
    try:
        api.files.delete(source_id)
        return "deleted"
    except IaGenifyError as error:
        if error.status == 404:
            return "already gone"
        raise

Updating a file does not re-index it, so a correction made with update() leaves the old text findable. When a document must stop being findable as it was, delete it and save the new version.