Parameters
sourceIdstringrequiredThe 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 otherwisefirst = 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 otherwiseWhat 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 sourceIdfrom 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_idnamestringThe file's name.
contentstring | BufferText as a string; anything else as a Buffer.
mimeTypestringWhat it was saved as.
sourceIdstringAlready set — update() works straight away.
location · metadataobjectWhere it lives, and what is recorded about it.
As a tool, it takes a path too
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
| Code | Status | When |
|---|---|---|
| file_not_found | 404 | No such file on this account. |
| file_missing_on_disk | 404 | The 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.