# Documents and Folders (/reference/public-api/documents)

## Add a document [#add-a-document]

<Tabs items={["Text","Link","File"]}>
<Tab value="Text">
```json title="POST /api/v1/documents"
{ "name": "notes.md", "source": { "type": "text", "text": "# Notes\n\nA document to read." } }
```

`name` must include a text or Markdown extension.
</Tab>

<Tab value="Link">
```json title="POST /api/v1/documents"
{ "source": { "type": "url", "url": "https://example.com/article" } }
```

A PDF, EPUB, DOCX, Markdown or text file is kept, up to the instance's upload limit. Its type comes from `Content-Type`, or from the file name when the server sends a generic type. A web page becomes readable Markdown.

The server fetches public HTTP(S) addresses and checks redirects. It cannot see pages that need your own sign-in, and private networks are blocked.
</Tab>

<Tab value="File">
```json title="POST /api/v1/documents"
{ "source": { "type": "upload", "uploadId": "..." } }
```

See [Uploads](/reference/public-api/uploads).
</Tab>
</Tabs>

Creation accepts an optional `folderId`; text and links also accept `author` and `language`. It returns `201`, a `Location` header and the document, except for a DOCX, which returns `202` with an upload resource while it converts (see [Uploads](/reference/public-api/uploads)).

The ID is the SHA-256 of the canonical file, so reimporting the same bytes reuses it. HTML pages and inline text are limited to 2 MB, and JSON document requests to 3 MB.

## Check that it is ready [#check-that-it-is-ready]

`GET /api/v1/documents/{id}` adds `status`, `operationId`, `error`, `fileUrl` and `webUrl`. Reading it never opens the reader, updates recent activity or starts parsing.

| Status | Meaning |
| --- | --- |
| `ready` | The document can be read and used for audio. |
| `not_started` | A PDF has not been parsed yet. Opening it or requesting an audiobook starts parsing. |
| `processing` | A PDF is being parsed. |
| `failed` | Parsing failed; `error` explains why. |
| `unknown` | The compute worker could not be reached. Read the status again later. |

## List and filter [#list-and-filter]

Lists return `{ "data": [...], "nextCursor": "..." }`. Keep requesting the returned cursor, unchanged, until it is `null`.

| Parameter | Effect |
| --- | --- |
| `limit` | 100 by default, 200 at most |
| `q` | A literal, case-insensitive part of the filename |
| `folderId` | One folder. Empty (`folderId=`) selects unfiled documents; omitted selects all. |
| `ids` | Up to 200 comma-separated IDs |

Documents are ordered by ID. Bulk moves and deletes also accept at most 200 IDs, and deletion always requires explicit IDs. Setting `folderId` to `null` moves a document out of its folder. Renaming or moving keeps its audio and version.

## Chapters and search [#chapters-and-search]

`GET /api/v1/documents/{id}/chapters` returns chapters in reading order. Each has `title`, `depth` (zero is top level), inclusive `startOrdinal` and `endOrdinal`, the first sentence's `segmentKey`, `page` (PDF only) and `webUrl`. Titles come from the document's contents or headings.

`GET /api/v1/documents/{id}/search?q=&limit=` finds text inside a document.

Use a `segmentKey` with a [reader `goto`](/reference/public-api/reader) to jump there.

<Callout title="New documents are prepared first">
Preparing counts toward compute limits. Until it finishes, chapters answer `409 DOCUMENT_PREPARING` with `retryAfterMs`.
</Callout>

Audiobook titles use the same contents but keep their own chapter boundaries, so several audio chapters may share a title.

## Folders [#folders]

`GET /api/v1/folders` is ordered by `position`, creation time and ID.

| To | Call |
| --- | --- |
| Create | `POST /api/v1/folders` with `name`, an optional `id`, and optional `documentIds` (at most 200) to move in atomically |
| Rename or reorder | `PATCH /api/v1/folders/{id}` with `name` and/or integer `position` |
| Delete one, or all | `DELETE /api/v1/folders/{id}`, or `DELETE /api/v1/folders` |

Deleting a folder **keeps its documents**, unfiled. Names are trimmed and limited to 200 characters. IDs are 1–100 letters, digits or hyphens. Folder write bodies are limited to 64 KB.