# readDocument()

Canonical URL: https://developers.iagenify.com/sdk/ref/tools/read-document/
Language: en

`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().

Status: GET /api/files/:id · free · content included

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `sourceId` | string | required | The identifier from [listDocuments()](/sdk/ref/tools/list-documents) or from a save. Missing raises immediately. |

```javascript
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
```

## What comes back {#returns}

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

```javascript
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
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `name` | string |  | The file's name. |
| `content` | string | Buffer |  | Text as a string; anything else as a Buffer. |
| `mimeType` | string |  | What it was saved as. |
| `sourceId` | string |  | Already set — `update()` works straight away. |
| `location · metadata` | object |  | Where it lives, and what is recorded about it. |

## As a tool, it takes a path too {#as-a-tool}

> **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 {#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.

- [api.files.get()](/sdk/ref/files/get): The same call on the files resource.
- [The agent's read](/sdk/agent/tools/read): What a local agent sees — documents, images, audio and video.
- [api.tools](/sdk/ref/tools): The fifteen, and the two ways to use them.

```python
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
```

```python
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
```
