api.tools

readDocument()

api.tools.readDocument(sourceId) → Promise<IaGenifyFile>

Reads one of the account's files back, content included. Free, and the same call as api.files.get().

GET /api/files/:idfreecontent included
Using Python?

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

Parameters

sourceIdstringrequired

The identifier from listDocuments() or from a save. Missing raises immediately.

const [first] = await api.tools.listDocuments();
const file = await api.tools.readDocument(first.id);

console.log(file.name, file.mimeType);
console.log(file.content);              // a string for text, a Buffer otherwise
first = api.tools.list_documents()["account"][0]
file = api.tools.read_document(first["id"])

print(file.name, file.mime_type)
print(file.content)              # a str for text, bytes otherwise

What comes back

An IaGenifyFile — the same object api.files.create() hands you, already carrying its sourceId. So reading, changing and putting it back is three lines.

const file = await api.tools.readDocument(id);
file.content = `${file.content}\n\nReviewed on ${new Date().toISOString().slice(0, 10)}.`;
await file.update();                    // replaces it, same sourceId
from datetime import date

file = api.tools.read_document(source_id)
file.content = f"{file.content}\n\nReviewed on {date.today().isoformat()}."
file.update()                    # replaces it, same source_id
namestring

The file's name.

contentstring | Buffer

Text as a string; anything else as a Buffer.

mimeTypestring

What it was saved as.

sourceIdstring

Already set — update() works straight away.

location · metadataobject

Where it lives, and what is recorded about it.

As a tool, it takes a path too

One parameter, two kinds of value

Declared to a model, its parameter is called document and it accepts either an id or a path on the caller's computer. An id is tried first; failing that, the path is read on the machine through the package. One tool for both sides, because a model should not have to know which it is holding.

A binary file read that way is reported as binary rather than returned as a mangled string — the model is told the name, the type and the size, and can ask for a conversion instead.

Errors

CodeStatusWhen
file_not_found404No such file on this account.
file_missing_on_disk404The record is there and the bytes are not.

A call with no sourceId throws before any request: it is a mistake in your code, not an answer from the platform.