# Knowledge Hub API guide

Parse documents with Docling, or store them in the Knowledge Hub, from your own code.

Use the Knowledge Hub from your own scripts and applications through the Pinter API. Documents are parsed with
**Docling** (OCR for scans, tables, page layout). You can use it in two ways:

- **Parse only**: send a file, get the parsed content back as JSON. Nothing is added to the Knowledge Hub.
- **Parse and store**: upload a file into the Knowledge Hub so it can be searched, cited, shared, and used by agents.

```mermaid
flowchart TD
    A[I have a file] --> B{Do I need Pinter to keep it<br />searchable for agents and users?}
    B -- No, I only want the parsed content --> P[Parse only<br />POST /api/knowledge/parse]
    B -- Yes --> S[Parse and store<br />POST /api/knowledge/documents/hub-upload]
    P --> P1[Poll status]
    P1 --> P2[Fetch result: document + chunks]
    P1 --> P3[Fetch layout: block positions]
    P2 --> P4[Delete output when done]
    S --> S1[Poll status until processed]
    S1 --> S2[Read chunks, layout, file]
    S1 --> S3[Search with hub-query]
    S1 --> S4[Share, organize, delete]
```

| | **Parse only** | **Parse and store** |
| --- | --- | --- |
| What you get | Parsed document (pages, blocks, tables, positions) and optionally chunks, as JSON | A stored, searchable document |
| Saved in the Knowledge Hub? | No. Temporary output you can delete at any time | Yes: file, chunks, embeddings, metadata |
| Searchable by agents and users | No | Yes |
| Sharing, folders | No | Yes |
| Processing | Asynchronous: start, poll, fetch | Asynchronous: upload, poll |
| Entry point | `POST /api/knowledge/parse` | `POST /api/knowledge/documents/hub-upload` |

## Contents

1. [Getting started](#1-getting-started)
2. [Parse only](#2-parse-only)
3. [Parse and store](#3-parse-and-store)
4. [Working with layout](#4-working-with-layout)
5. [Errors, limits, and supported files](#5-errors-limits-and-supported-files)
6. [Endpoint index](#6-endpoint-index)

---

## 1. Getting started

### Authentication

Create a personal API key in the Pinter app: user menu, **Platform API Keys**. Keys look like `sk_...`, are shown
only once, and act with your permissions. Keep them out of source control.

```bash
export BASE=https://<pinter-host>
export KEY=sk_...
curl -H "Authorization: Bearer $KEY" "$BASE/api/knowledge/documents/hub-documents"
```

```mermaid
sequenceDiagram
    actor Dev as You
    participant App as Pinter app
    participant API as Pinter API
    Dev->>App: Create a Platform API Key (sk_...)
    App-->>Dev: Key, shown once
    Dev->>API: Request with Authorization: Bearer sk_...
    API-->>Dev: Response, with your permissions applied
```

### Conventions

- Every endpoint is under `/api`. Requests with a file are `multipart/form-data`; others are JSON.
- Ids are UUIDs.
- Errors return `{"detail": "..."}` with a standard HTTP status: `401` not signed in, `403` not allowed, `404` not found
  (also used when something exists but is not yours), `409` wrong state, `413` file too large, `415` unsupported
  file type, `422` invalid input, `429` too many requests, `503` temporarily unavailable.
- Error text can be in Indonesian for the stored-document endpoints. Use the HTTP status and `error_code` for logic,
  not the text.
- Your role decides what you can do. Creating documents needs role level 2 or higher, and read-only (auditor)
  accounts cannot create or change anything.

---

## 2. Parse only

Send a file, let Docling parse it, and fetch the result. Only the account that started a job can see it.

```mermaid
sequenceDiagram
    actor Dev as Your app
    participant API as Pinter API
    participant P as Docling parser
    Dev->>API: POST /api/knowledge/parse (file, mode)
    API-->>Dev: 202 job_id, status=processing
    API->>P: Parse the file
    loop every few seconds
        Dev->>API: GET /api/knowledge/parse/{job_id}
        API-->>Dev: status processing | succeeded | failed
    end
    P-->>API: Output ready, your upload is deleted
    Dev->>API: GET /api/knowledge/parse/{job_id}/result
    API-->>Dev: document (+ chunks)
    Dev->>API: GET /api/knowledge/parse/{job_id}/layout
    API-->>Dev: block positions
    Dev->>API: DELETE /api/knowledge/parse/{job_id}
    API-->>Dev: 204
```

```mermaid
stateDiagram-v2
    [*] --> processing: POST /parse
    processing --> succeeded: output ready
    processing --> failed: error_code set
    succeeded --> [*]: DELETE
    failed --> [*]: DELETE
```

### 2.1 Start a job: `POST /api/knowledge/parse`

```bash
curl -X POST "$BASE/api/knowledge/parse" \
  -H "Authorization: Bearer $KEY" \
  -F "file=@report.pdf" \
  -F "mode=chunk"
```

| Form field | Required | Values | Meaning |
| --- | --- | --- | --- |
| `file` | yes | | The document to parse |
| `mode` | no | `parse` (default), `chunk` | `parse` returns the document structure. `chunk` also returns the text split into chunks, the same chunks the Knowledge Hub would index |

Response `202`:

```json
{"job_id": "5b0f1c0e-6d0a-4a4e-9a52-0c1f4d9a7a10", "filename": "report.pdf", "mode": "chunk", "status": "processing"}
```

Errors: `403` role cannot create documents, `413` file over 100 MB, `415` unsupported type, `422` empty file, content
that does not match the extension, or invalid `mode`, `429` over 20 requests per minute, `503` parsing not available.

### 2.2 Check status: `GET /api/knowledge/parse/{job_id}`

```bash
curl -H "Authorization: Bearer $KEY" "$BASE/api/knowledge/parse/$JOB_ID"
```

```json
{
  "job_id": "5b0f1c0e-6d0a-4a4e-9a52-0c1f4d9a7a10",
  "filename": "report.pdf",
  "mode": "chunk",
  "status": "succeeded",
  "page_count": 12,
  "chunk_count": 34,
  "warnings": [],
  "duration_ms": 11322,
  "timings_ms": {"download": 40, "prepare": 310, "convert": 9800, "chunk": 70},
  "error_code": null,
  "error_message": null
}
```

| Field | Meaning |
| --- | --- |
| `status` | `processing`, `succeeded`, or `failed` |
| `page_count` | Pages found. For formats without pages this is an estimate |
| `chunk_count` | Number of chunks. `null` in `parse` mode |
| `warnings` | Notes such as `converted_from:doc` or `docling_partial_success:2` |
| `duration_ms`, `timings_ms` | Total time and time per stage |
| `error_code`, `error_message` | Set when `status` is `failed`. See [parse error codes](#parse-error-codes) |

Poll every few seconds. Small documents take seconds, large scans take minutes. A job stuck for over an hour is
reported as `failed` with `internal_error`.

### 2.3 Get the result: `GET /api/knowledge/parse/{job_id}/result`

```bash
curl -H "Authorization: Bearer $KEY" "$BASE/api/knowledge/parse/$JOB_ID/result" -o result.json
curl -H "Authorization: Bearer $KEY" "$BASE/api/knowledge/parse/$JOB_ID/result?parts=chunks"
```

| Query parameter | Meaning |
| --- | --- |
| `parts` | Optional, comma separated subset of `document`, `chunks`. Use it to skip the large `document` part |

Returns `409` while the job is running or after it failed (the body then holds `error_code` and `error_message`),
and `404` if the job does not exist or is not yours.

```json
{
  "schema_version": 1,
  "mode": "chunk",
  "document": {
    "pages": [{"page_number": 1, "width": 595.0, "height": 842.0}],
    "blocks": [
      {"source_id": "p1-b3", "page_number": 1, "kind": "text",
       "text": "Revenue grew 12% ...", "bbox": [0.05, 0.10, 0.95, 0.18], "warnings": []}
    ],
    "warnings": []
  },
  "chunks": [
    {"chunk_index": 0, "kind": "text", "page_start": 1, "page_end": 1, "locator": "halaman 1",
     "source_ids": ["p1-b3"], "warnings": [], "content": "Document: report\n\nRevenue grew 12% ..."}
  ]
}
```

| Field | Meaning |
| --- | --- |
| `document.pages[]` | One entry per page with `page_number`, `width`, `height` |
| `document.blocks[]` | Every piece of content, in reading order |
| `blocks[].source_id` | Id of the block inside this result. Chunks point back to it |
| `blocks[].kind` | `text`, `heading`, `table`, `image`, `footnote`, or `formula` |
| `blocks[].text` | The block's text. A table has one row per line, cells separated by a pipe character |
| `blocks[].bbox` | `[x0, y0, x1, y1]`, values 0 to 1, origin at the top left. `null` when unknown |
| `chunks[]` | Only in `chunk` mode |
| `chunks[].content` | The chunk text, starting with a `Document:` line |
| `chunks[].source_ids` | The blocks this chunk was built from |
| `chunks[].locator` | A page reference. The text is Indonesian: `halaman 3` means page 3. It is `null` for formats without real pages |

### 2.4 Get the layout: `GET /api/knowledge/parse/{job_id}/layout`

Yes, parse output has a layout too. It is the list of block positions that you can use to draw highlights over a page
image. It is derived from the same output but small, because it keeps only what you need to draw.

```bash
curl -H "Authorization: Bearer $KEY" "$BASE/api/knowledge/parse/$JOB_ID/layout"
```

```json
{
  "blocks": [
    {"source_id": "p1-b3", "kind": "text", "page_number": 1, "bbox": [0.05, 0.10, 0.95, 0.18], "text": "Revenue grew 12% ..."},
    {"source_id": "p1-b5", "kind": "table", "page_number": 1, "bbox": null, "text": "Q1 | Q2\n10 | 12"}
  ]
}
```

`text` is cut at 2000 characters, and blocks without a usable id or page are left out. See
[section 4](#4-working-with-layout) for how to use it.

### 2.5 Delete the output: `DELETE /api/knowledge/parse/{job_id}`

Your uploaded file is deleted as soon as parsing finishes. The output stays so you can fetch it more than once; delete
it when you are done. Returns `204`.

### 2.6 Complete example (Python)

```python

base = os.environ["BASE"]
h = {"Authorization": f"Bearer {os.environ['KEY']}"}

job = requests.post(f"{base}/api/knowledge/parse", headers=h,
                    files={"file": open("report.pdf", "rb")},
                    data={"mode": "chunk"})
job.raise_for_status()
job_id = job.json()["job_id"]

while True:
    st = requests.get(f"{base}/api/knowledge/parse/{job_id}", headers=h).json()
    if st["status"] != "processing":
        break
    time.sleep(3)

if st["status"] == "failed":
    raise RuntimeError(f"{st['error_code']}: {st['error_message']}")

result = requests.get(f"{base}/api/knowledge/parse/{job_id}/result", headers=h).json()
layout = requests.get(f"{base}/api/knowledge/parse/{job_id}/layout", headers=h).json()

for chunk in result["chunks"]:
    print(chunk["locator"], chunk["content"][:80])

requests.delete(f"{base}/api/knowledge/parse/{job_id}", headers=h)
```

### Parse error codes

| `error_code` | Meaning | What to do |
| --- | --- | --- |
| `encrypted_pdf` | The PDF is password protected | Remove the password |
| `unreadable_pdf` | The PDF is corrupted | Re-export the file |
| `too_many_pages` | More than 500 pages | Split the document |
| `no_text` | No text could be extracted | Check the file has readable content |
| `conversion_failed` | The document could not be converted | Re-save in a current format |
| `office_conversion_failed`, `office_conversion_timeout`, `office_unavailable` | Converting an older Office file failed | Save as DOCX, XLSX, or PPTX and retry |
| `source_unavailable`, `invalid_request` | The input could not be used | Upload again |
| `internal_error` | Temporary problem on the Pinter side | Start a new job; contact support if it repeats |

---

## 3. Parse and store

Upload a document into the Knowledge Hub. Pinter parses it, splits it into chunks, embeds them, and makes it
searchable. You then read, search, share, organize, and delete it through the API.

```mermaid
sequenceDiagram
    actor Dev as Your app
    participant API as Pinter API
    participant P as Docling parser
    participant I as Search index
    Dev->>API: POST /documents/hub-upload (file, metadata)
    API-->>Dev: 201 document id, status=uploaded
    API->>P: Parse, chunk, embed
    P->>I: Store chunks
    loop every few seconds
        Dev->>API: GET /documents/hub-documents/{id}
        API-->>Dev: status processing | processed | failed
    end
    Dev->>API: POST /documents/hub-query (question)
    API->>I: Search only documents you may see
    I-->>API: Best matching chunks
    API-->>Dev: Results with document and page reference
```

```mermaid
stateDiagram-v2
    [*] --> uploaded: hub-upload
    uploaded --> processing
    processing --> processed: success
    processing --> failed: error_code set
    failed --> uploaded: POST reprocess
    processed --> [*]: DELETE
    failed --> [*]: DELETE
```

### 3.1 Upload: `POST /api/knowledge/documents/hub-upload`

```bash
curl -X POST "$BASE/api/knowledge/documents/hub-upload" \
  -H "Authorization: Bearer $KEY" \
  -F "file=@report.pdf" \
  -F "description=Annual report 2025" \
  -F "categories=finance" \
  -F "keywords=revenue,2025" \
  -F "visibility=private" \
  -F "folder_path=Finance/2025"
```

Returns `201` immediately with the document record (see [3.3](#33-read-a-document)). Parsing continues in the
background.

| Form field | Meaning |
| --- | --- |
| `file` | Required. The document |
| `description`, `categories`, `keywords` | Free text metadata (description up to 5000 characters, the others up to 1000) |
| `folder_path` | Folder to place it in, for example `Finance/2025`. Created if it does not exist |
| `visibility` | `private` (default) or `internal` (whole organization; needs the right to share organization wide) |
| `share_permission` | `use` (default) or `view` (view only, no use by agents) for people it is shared with |
| `share_expires_at` | When sharing expires |
| `grantee_user_ids`, `grantee_group_ids` | Ids of users and role groups to share with |
| `grantees` | JSON list `[{"type": "user", "id": "...", "permission": "view"}]` for a level per recipient. `type` is `user` or `role_group`; `permission` is `view`, `use`, or `manage` |
| `table_semantics` | JSON describing columns, for CSV and Excel files |

Spreadsheets and CSV files are not chunked. They are ready right away and are queried as tables
([3.6](#36-query-spreadsheets-and-csv-files)).

### 3.2 Wait for processing

Poll the document until `status` is `processed` or `failed`.

```bash
curl -H "Authorization: Bearer $KEY" "$BASE/api/knowledge/documents/hub-documents/$DOCUMENT_ID?include=none"
```

`include=none` skips the chunk preview, which keeps polling cheap.

On `failed`, `error_code` and `error_message` explain why. The codes are the same as the
[parse error codes](#parse-error-codes), plus `embedding_failed` and `index_failed` for temporary problems on the
Pinter side. Retry a failed document without uploading it again:

```bash
curl -X POST -H "Authorization: Bearer $KEY" "$BASE/api/knowledge/documents/hub-documents/$DOCUMENT_ID/reprocess"
```

This works only on a `failed` document (otherwise `409`) and needs manage rights on it.

```python

base, h = os.environ["BASE"], {"Authorization": f"Bearer {os.environ['KEY']}"}
docs = f"{base}/api/knowledge/documents"

doc = requests.post(f"{docs}/hub-upload", headers=h, files={"file": open("report.pdf", "rb")}).json()

while True:
    d = requests.get(f"{docs}/hub-documents/{doc['id']}", params={"include": "none"}, headers=h).json()
    if d["status"] in ("processed", "failed"):
        break
    time.sleep(3)

print(d["status"], d.get("error_code"), d.get("chunk_count"), d.get("page_count"))
```

### 3.3 Read a document

**List:** `GET /api/knowledge/documents/hub-documents`

| Query parameter | Meaning |
| --- | --- |
| `search` | Match on name and metadata |
| `document_type` | Filter by file type, for example `pdf` |
| `status` | `uploaded`, `processing`, `processed`, `failed` |
| `uploader_id` | Filter by uploader |
| `folder_path`, `include_subfolders` | Only this folder, and optionally everything under it |
| `limit` (up to 200), `offset` | Paging |

Returns `{"items": [...], "total": N}` with only documents you may see.

**Detail:** `GET /api/knowledge/documents/hub-documents/{document_id}`

| `include` | Adds |
| --- | --- |
| `chunks` | The first 50 chunks (`chunk_total` has the full count) |
| `preview` | A text preview |
| `tabular` | Table information for spreadsheets |
| `none` | Nothing extra |

Several values can be combined with commas. A document looks like this:

```json
{
  "id": "11111111-1111-4111-8111-111111111111",
  "filename": "report.pdf",
  "document_type": "pdf",
  "status": "processed",
  "description": "Annual report 2025",
  "categories": "finance",
  "keywords": "revenue,2025",
  "folder_path": "Finance/2025",
  "visibility": "private",
  "share_permission": "use",
  "share_expires_at": null,
  "size_bytes": 482113,
  "page_count": 12,
  "chunk_count": 34,
  "version_number": 1,
  "error_code": null,
  "error_message": null,
  "created_at": "2026-11-26T08:07:20Z",
  "can_attach": true,
  "can_download": true,
  "can_manage_access": true
}
```

**Update metadata:** `PATCH /api/knowledge/documents/hub-documents/{document_id}` with JSON. Any of `description`,
`categories`, `keywords`, `folder_path`, `visibility`, `table_semantics`. Needs manage rights.

**Chunks, paged:** `GET .../hub-documents/{document_id}/chunks?offset=0&limit=50` (limit up to 100)

```json
{
  "total": 75, "offset": 0, "limit": 50,
  "items": [
    {"id": "6f1c2a9e-...", "chunk_index": 0, "content": "...",
     "meta": {"locator": "halaman 7", "page_start": 7, "page_end": 7, "kind": "text", "source_ids": ["p7-b2"]}}
  ]
}
```

**Chunk by block:** `GET .../chunks/by-source?source_id=p7-b2` returns the chunk that contains that layout block. Use it
to go from a highlighted block to its text. `source_id` may contain letters, digits, `_ . : -`, up to 64 characters.

**Layout:** `GET .../hub-documents/{document_id}/layout` returns `{"blocks": [...]}`. See
[section 4](#4-working-with-layout). It returns `404` until the document is `processed`.

**Original file:** `GET .../hub-documents/{document_id}/file` downloads the file you uploaded.

`meta.locator` is a page reference whose text is Indonesian (`halaman 7` means page 7). It is missing for formats
without real pages, so do not use page numbers from those as citations.

### 3.4 Search: `POST /api/knowledge/documents/hub-query`

```bash
curl -X POST "$BASE/api/knowledge/documents/hub-query" \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"query": "What was revenue in 2025?", "top_k": 5, "threshold": 0.5,
       "filters": {"document_ids": ["11111111-1111-4111-8111-111111111111"]}}'
```

| Field | Required | Meaning |
| --- | --- | --- |
| `query` | yes | Your question in natural language, up to 4000 characters |
| `top_k` | no | Number of results, 1 to 20 (default 5) |
| `threshold` | no | Minimum similarity score. Lower scoring results are dropped |
| `filters.document_ids` | no | Search only these documents |

```json
{
  "query": "What was revenue in 2025?",
  "total": 1,
  "results": [
    {
      "chunk_id": "...", "chunk_index": 12, "similarity": 0.83,
      "content": "Revenue grew 12% ...",
      "metadata": {"locator": "halaman 7", "page_start": 7, "page_end": 7, "kind": "text"},
      "document": {"id": "1111...", "filename": "report.pdf", "document_type": "pdf",
                   "uploader_id": "...", "uploader_name": "Dewi"}
    }
  ]
}
```

Search is semantic and covers only `processed` documents you are allowed to see: your own, and those shared with you
that have not expired. Results are ordered by `similarity`. `"truncated": true` appears if you can see more documents
than one search covers; narrow it with `filters.document_ids`.

### 3.5 Share, organize, delete

**Sharing:** `GET .../hub-documents/{document_id}/share` shows the current policy and recipients.
`PATCH` the same path changes it:

```bash
curl -X PATCH "$BASE/api/knowledge/documents/hub-documents/$DOCUMENT_ID/share" \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"visibility": "private", "permission": "use", "expires_in_hours": 168,
       "grantees": [{"type": "user", "id": "USER_ID", "permission": "view"}]}'
```

| Field | Values |
| --- | --- |
| `visibility` | `private` or `internal` |
| `permission` | `view` or `use` |
| `expires_in_hours` | `1`, `24`, `168`, `720`, or `null` for no expiry |
| `grantee_user_ids`, `grantee_group_ids` | Ids of recipients |
| `grantees` | Recipients with a level each: `view`, `use`, or `manage` |

**Delete:** `DELETE .../hub-documents/{document_id}` removes the document and its search data. Needs manage rights.

**Folders** group documents (`folder_path` on upload and update):

| Call | Purpose |
| --- | --- |
| `GET /api/knowledge/folders?parent_path=&search=` | List folders |
| `GET /api/knowledge/folders/tree` | The full folder tree |
| `POST /api/knowledge/folders` | Create. JSON `{"path": "Finance/2025", "visibility": "private"}` |
| `PATCH /api/knowledge/folders/move` | Move. JSON `{"source_path": "...", "destination_path": "..."}` |
| `DELETE /api/knowledge/folders?path=...` | Delete a folder |

**Collections** bundle documents so they can be shared or attached to agents together:

| Call | Purpose |
| --- | --- |
| `GET /api/knowledge/collections?search=&limit=&offset=` | List |
| `POST /api/knowledge/collections` | Create. JSON `{"name": "...", "description": "..."}` |
| `POST /api/knowledge/collections/from-folder` | Create from a folder. JSON `{"folder_path": "...", "name": "..."}` |
| `GET`, `PATCH`, `DELETE /api/knowledge/collections/{collection_id}` | Read, rename, delete |
| `POST /api/knowledge/collections/{collection_id}/documents` | Add documents. JSON `{"document_ids": ["..."]}` |
| `DELETE /api/knowledge/collections/{collection_id}/documents/{document_id}` | Remove a document |
| `GET`, `PATCH /api/knowledge/collections/{collection_id}/share` | Read or change sharing |

### 3.6 Query spreadsheets and CSV files

CSV and Excel files are stored as tables and are queried with SQL or a structured query instead of text search.

| Call | Purpose |
| --- | --- |
| `GET .../hub-documents/{document_id}/tables` | List tables and columns |
| `GET .../hub-documents/{document_id}/tables/{table}/rows?limit=` | Preview rows |
| `POST .../hub-documents/{document_id}/tables/query` | Run one read-only `SELECT`. JSON `{"sql": "SELECT ...", "limit": 100}` |
| `POST .../hub-documents/{document_id}/tables/select` | Structured query (columns, filters, aggregations), no SQL |
| `GET .../hub-documents/{document_id}/table-semantics` | Read column descriptions |
| `POST .../hub-documents/{document_id}/table-semantics/suggest` | Ask Pinter to suggest column descriptions |

```bash
curl -X POST "$BASE/api/knowledge/documents/hub-documents/$DOCUMENT_ID/tables/query" \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"sql": "SELECT region, SUM(revenue) AS total FROM sheet1 GROUP BY region", "limit": 50}'
```

Use `GET .../tables` first to see the real table and column names.

---

## 4. Working with layout

A layout is a list of **blocks**: pieces of content (paragraph, heading, table, image, footnote, formula) with where
they sit on a page. Use it to highlight text in a PDF viewer, to link a search result back to the exact spot, or to
find tables.

| | Parse only | Stored document |
| --- | --- | --- |
| Endpoint | `GET /api/knowledge/parse/{job_id}/layout` | `GET /api/knowledge/documents/hub-documents/{id}/layout` |
| Shape | `{"blocks": [...]}` | `{"blocks": [...]}` |
| Block fields | `source_id`, `kind`, `page_number`, `bbox`, `text` | Same |
| Also in the result | `document.blocks` (the same blocks plus `warnings`) | |

`bbox` is `[x0, y0, x1, y1]` as fractions of the page width and height, origin at the top left. To draw a box on a page
image that is `W` by `H` pixels:

```python
x0, y0, x1, y1 = block["bbox"]
rect = (x0 * W, y0 * H, x1 * W, y1 * H)
```

```mermaid
flowchart LR
    Q[Search result or chunk] -->|source_ids| B[Layout blocks]
    B -->|page_number + bbox| H[Draw highlight on the page image]
    U[User clicks a block] -->|source_id| C[GET chunks/by-source]
    C --> T[Show the chunk text]
```

Notes:

- `bbox` can be `null` when the position is unknown. Skip drawing, but keep the text.
- Non-PDF files (Word, Excel, HTML, text) have no real pages. Their `page_number` is an estimate, so do not use it as
  a citation.
- Chunks list the blocks they were built from in `source_ids`, so you can go from a chunk to its position.
- The block `text` in a layout is cut at 2000 characters. For the full text, use `document.blocks` (parse only) or the
  chunks (stored).

---

## 5. Errors, limits, and supported files

| Limit | Value |
| --- | --- |
| File size | 100 MB |
| PDF pages | 500 |
| Parse jobs | 20 requests per minute per account |
| Search results `top_k` | 1 to 20 |
| Search `query` | 4000 characters |
| List `limit` | up to 200 |
| Chunk page `limit` | up to 100 |

**Supported files:** PDF (digital and scanned), DOCX, PPTX, XLSX, CSV, HTML, Markdown, AsciiDoc, TXT, and images
(PNG, JPEG, TIFF, BMP, WebP). Older Office files (`.doc`, `.xls`, `.ppt`, `.rtf`, `.odt`, `.ods`, `.odp`) are converted
first. The file content must match its extension, or the upload is rejected with `422`.

**Do not** put sensitive information in file names; names can appear in logs.

| Status | Typical cause |
| --- | --- |
| `401` | Missing or invalid API key |
| `403` | Your role cannot do this, or you are not allowed on that document |
| `404` | Does not exist, or is not yours or not shared with you |
| `409` | Wrong state: result requested while running, or reprocess on a document that has not failed |
| `413` | File over 100 MB |
| `415` | Unsupported file type |
| `422` | Invalid input: empty file, wrong content, bad parameter |
| `429` | Too many requests. Wait and retry |
| `503` | Temporary problem. Retry with a short delay |

---

## 6. Endpoint index

All paths start with `/api/knowledge`.

**Parse only**

| Method | Path | Purpose |
| --- | --- | --- |
| `POST` | `/parse` | Start a parse job |
| `GET` | `/parse/{job_id}` | Job status |
| `GET` | `/parse/{job_id}/result` | Parsed document and chunks |
| `GET` | `/parse/{job_id}/layout` | Block positions |
| `DELETE` | `/parse/{job_id}` | Delete the output |

**Parse and store**

| Method | Path | Purpose |
| --- | --- | --- |
| `POST` | `/documents/hub-upload` | Upload and index a document |
| `GET` | `/documents/hub-documents` | List documents |
| `GET` | `/documents/hub-documents/{id}` | Document detail and status |
| `PATCH` | `/documents/hub-documents/{id}` | Update metadata |
| `DELETE` | `/documents/hub-documents/{id}` | Delete |
| `POST` | `/documents/hub-documents/{id}/reprocess` | Retry a failed document |
| `GET` | `/documents/hub-documents/{id}/chunks` | Chunks, paged |
| `GET` | `/documents/hub-documents/{id}/chunks/by-source` | Chunk for a layout block |
| `GET` | `/documents/hub-documents/{id}/layout` | Block positions |
| `GET` | `/documents/hub-documents/{id}/file` | Download the original |
| `GET`, `PATCH` | `/documents/hub-documents/{id}/share` | Read or change sharing |
| `POST` | `/documents/hub-query` | Semantic search |
| `GET` | `/documents/hub-documents/{id}/tables` | List tables |
| `GET` | `/documents/hub-documents/{id}/tables/{table}/rows` | Preview rows |
| `POST` | `/documents/hub-documents/{id}/tables/query` | Read-only SQL |
| `POST` | `/documents/hub-documents/{id}/tables/select` | Structured query |
| `GET` | `/documents/hub-documents/{id}/table-semantics` | Column descriptions |
| `POST` | `/documents/hub-documents/{id}/table-semantics/suggest` | Suggest column descriptions |
| `GET`, `POST`, `DELETE` | `/folders` | List, create, delete folders |
| `GET` | `/folders/tree` | Folder tree |
| `PATCH` | `/folders/move` | Move a folder |
| `GET`, `POST` | `/collections` | List, create collections |
| `POST` | `/collections/from-folder` | Collection from a folder |
| `GET`, `PATCH`, `DELETE` | `/collections/{id}` | Read, update, delete |
| `POST`, `DELETE` | `/collections/{id}/documents[/{document_id}]` | Add or remove documents |
| `GET`, `PATCH` | `/collections/{id}/share` | Read or change sharing |
