Adding documents¶
Five endpoints add documents to a project: file upload, text in the request body, web pages, S3 objects, and sync, which re-reads web and S3 documents. All of them answer with the same upload response. See Ingestion and Text, web pages and S3 for the concepts.
Paths are relative to /api/v1, and all need a write key. The examples
use BASE=http://localhost:8000/api/v1 and an API key in $KEY.
Common options¶
The JSON endpoints (text, url, s3) all take these fields. The upload
endpoint takes the same ones as form fields.
| Field | Type | Default | |
|---|---|---|---|
metadata |
object | none | Metadata for every document added. Omitted: a new version keeps the previous version's metadata |
on_conflict |
string | new_version |
new_version, skip or keep_both; see Conflicts |
access |
object | none | Who may see the documents. Omitted: public for a new document; a new version keeps the previous version's access |
chunking |
object | the project's | Chunking options for these documents |
process |
boolean | true |
Extract, chunk and index. false: only store them (status created); process them later with POST .../process |
background |
boolean | false |
Return at once and do the work as a job. The response has a job_id |
When the project's graph has auto_build, every request that adds or
changes documents also queues a graph build of the new chunks.
POST /projects/{project_id}/documents¶
Upload files. Each file becomes a document. ZIP and TAR archives are expanded, and each file in them becomes a document.
Body: multipart/form-data
| Field | Type | Default | |
|---|---|---|---|
files |
file, repeated | required | One field per file. At most FILE_MAX_FILES_PER_REQUEST (50) per request; more gives 400 |
process |
boolean | true |
See Common options |
background |
boolean | false |
|
metadata |
string | none | A JSON object, for example {"team": "legal", "year": 2025} |
external_id |
string | the file name | Your id for the file, up to 2048 characters. Only with exactly one file that is not an archive; otherwise 400 |
access |
string | none | A JSON access object |
on_conflict |
string | new_version |
new_version, skip or keep_both |
| chunking fields | the project's | Each chunking option as a field of its own: strategy, chunk_size, chunk_overlap, extractor, length_unit, token_encoding, separators (repeated), separators_regex, language, rows_per_chunk, table_format, semantic_threshold_type, semantic_threshold_amount, semantic_buffer_size, contextual_header, llm_context, parent_chunk_size |
Limits (from the settings):
| Setting | Default | |
|---|---|---|
FILE_MAX_SIZE_MB |
100 | A larger file, or archive member, is rejected |
FILE_MAX_FILES_PER_REQUEST |
50 | Files per request |
ARCHIVE_MAX_FILES |
1000 | Files expanded from one archive |
ARCHIVE_MAX_TOTAL_SIZE_MB |
1024 | Total expanded size of one archive |
Archive entries with unsafe paths, and archives inside archives, are
rejected.
GET /data/file-types lists the supported file types.
Response: 200 with the upload response.
Errors:
| Status | When |
|---|---|
| 400 | Too many files, bad metadata or access JSON, or external_id with several files or an archive |
| 404 | The project does not exist |
| 422 | Invalid chunking options |
# Two files, with metadata and access
curl -X POST "$BASE/projects/1/documents" -H "Authorization: Bearer $KEY" \
-F files=@handbook.pdf -F files=@benefits.docx \
-F metadata='{"team": "hr", "year": 2026}' \
-F access='{"groups": ["staff"]}'
# One file under your own id, with its own chunking, processed by a job
curl -X POST "$BASE/projects/1/documents" -H "Authorization: Bearer $KEY" \
-F files=@contract.pdf -F external_id=contract-2291 \
-F strategy=page -F background=true
# A ZIP of a folder, stored but not indexed yet
curl -X POST "$BASE/projects/1/documents" -H "Authorization: Bearer $KEY" \
-F files=@docs.zip -F process=false
POST /projects/{project_id}/documents/text¶
Add text, Markdown, HTML or JSON sent in the request body. Each item becomes a document.
Body (JSON, unknown fields refused): the common options, plus:
| Field | Type | |
|---|---|---|
items |
list, 1 to 1000 | The documents. Required |
Each item (unknown fields refused):
| Field | Type | Default | |
|---|---|---|---|
text |
string | The content: plain text, Markdown or HTML. Can't be blank | |
json |
any JSON value | Instead of text: stored as a .json document and split by the json strategy |
|
format |
string | from file_name's extension, else text |
text, markdown or html. Only with text |
file_name |
string, 1 to 512 characters | text-<hash>.<ext> |
Shown in results and citations |
external_id |
string, 1 to 2048 characters | the file name | Your id. Sending it again makes a new version |
metadata |
object | Merged over the request's metadata |
|
access |
object | Used instead of the request's access |
Give exactly one of text and json.
Response: 200 with the upload response.
curl -X POST "$BASE/projects/1/documents/text" -H "Authorization: Bearer $KEY" \
-H 'Content-Type: application/json' -d '{
"metadata": {"source": "wiki"},
"items": [
{"text": "# Leave\n\nStaff get 25 days of paid leave.", "format": "markdown",
"file_name": "leave.md", "external_id": "wiki:leave",
"metadata": {"team": "hr"}},
{"json": {"sku": "A-100", "name": "Desk", "price": 199},
"file_name": "a-100.json", "access": {"groups": ["sales"]}}
]
}'
POST /projects/{project_id}/documents/url¶
Import web pages or files by URL. Each one becomes a document whose
external_id is its URL. HTML pages can be crawled: with max_depth their
links are followed, and with use_sitemaps (or a sitemap URL) the site's
sitemaps are read.
Body (JSON, unknown fields refused): the common options, plus:
| Field | Type | Allowed values | Default | |
|---|---|---|---|---|
urls |
list of strings | 1 to 100 URLs, each 1 to 2048 characters | required | Pages, files (PDF, DOCX, ...) or XML sitemaps (their pages are imported) |
max_depth |
integer | 0 to 10 | 0 |
Follow links this many clicks away. 0: only the given URLs |
max_pages |
integer | 1 or more | URL_MAX_PAGES (500) |
The most pages fetched. A larger value is lowered to URL_MAX_PAGES, with a warning |
same_domain |
boolean | true |
Follow links only on the given URLs' hosts. www. counts as the same host |
|
include |
list of globs | up to 50, each 1 to 512 characters | [] |
Only URLs matching one of them, on the full URL or its path, such as /docs/* |
exclude |
list of globs | up to 50 | [] |
Skip URLs matching any of them |
use_sitemaps |
boolean | false |
Also import the pages in each site's sitemaps (from robots.txt, else /sitemap.xml) |
|
respect_robots_txt |
boolean | true |
Obey robots.txt, its crawl delay and robots meta tags (noindex) |
How fetching works:
- Requests are spaced by
URL_CRAWL_DELAY_MS(250), or the robots.txt crawl delay when it is longer. - Each request times out after
URL_FETCH_TIMEOUT_SECONDS(30), and is sent asURL_USER_AGENT(PageloreBot/0.1). - URLs on private networks (localhost, 10.x, 192.168.x, ...) are refused
with 403, unless
URL_ALLOW_PRIVATE_NETWORKSis on. Redirects are checked the same way. - A page imported before is asked for with its ETag and Last-Modified. If
it did not change, its result is
unchanged. - With
background: true, the response has ajob_idand an emptyresults. The documents appear as they are imported.
The response's stats count what the crawl did: fetched,
robots_blocked, excluded, external, noindex, not_fetched,
redirect_duplicates, sitemaps.
Errors: 403 (a private network address), 404, 422; a site that fails
gives that page a failed result.
# Two pages
curl -X POST "$BASE/projects/1/documents/url" -H "Authorization: Bearer $KEY" \
-H 'Content-Type: application/json' \
-d '{"urls": ["https://example.com/pricing", "https://example.com/terms.pdf"]}'
# Crawl the docs section of a site, two clicks deep, as a job
curl -X POST "$BASE/projects/1/documents/url" -H "Authorization: Bearer $KEY" \
-H 'Content-Type: application/json' -d '{
"urls": ["https://docs.example.com/"],
"max_depth": 2, "max_pages": 200,
"include": ["/guide/*", "/api/*"], "exclude": ["*/changelog*"],
"use_sitemaps": true,
"metadata": {"source": "docs-site"},
"background": true
}'
POST /projects/{project_id}/documents/s3¶
Import objects from an S3 bucket (or MinIO, R2 and other S3-compatible
stores): everything under a prefix, or exactly the given keys. Each object
becomes a document keyed s3://bucket/key. Credentials come from the
server's S3_* settings (S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY,
S3_SESSION_TOKEN, S3_REGION, S3_ENDPOINT_URL, S3_ADDRESSING_STYLE),
or boto3's own chain. Needs the s3 extra (boto3).
Body (JSON, unknown fields refused): the common options, plus:
| Field | Type | Allowed values | Default | |
|---|---|---|---|---|
bucket |
string | 1 to 255 characters | required | When S3_BUCKETS is set, the bucket must be in it |
prefix |
string | up to 1024 characters | "" (the whole bucket) |
Import every object under it |
keys |
list of strings | 1 to 1000 keys, each 1 to 1024 characters | none | Exactly these objects. Can't be combined with prefix, include or exclude |
include |
list of globs | up to 50 | [] |
Only keys matching one of them, on the full key or its last part, such as *.pdf |
exclude |
list of globs | up to 50 | [] |
Skip keys matching any of them |
max_objects |
integer | 1 or more | S3_MAX_OBJECTS (1000) |
The most objects imported |
An object whose ETag did not change since it was imported is not
downloaded again; its result is unchanged.
Errors:
| Status | When |
|---|---|
| 403 | The bucket is not in S3_BUCKETS |
| 404 | The project, the bucket or a key does not exist |
| 409 | boto3 is not installed |
| 413 | An object is over FILE_MAX_SIZE_MB |
| 422 | keys together with prefix, include or exclude, or invalid fields |
| 502 | S3 failed, for example bad credentials |
# Every PDF under a prefix
curl -X POST "$BASE/projects/1/documents/s3" -H "Authorization: Bearer $KEY" \
-H 'Content-Type: application/json' -d '{
"bucket": "acme-docs", "prefix": "policies/2026/",
"include": ["*.pdf"], "exclude": ["drafts/*"],
"metadata": {"source": "s3"}, "background": true
}'
# Exactly two objects
curl -X POST "$BASE/projects/1/documents/s3" -H "Authorization: Bearer $KEY" \
-H 'Content-Type: application/json' \
-d '{"bucket": "acme-docs", "keys": ["policies/leave.pdf", "policies/travel.docx"]}'
POST /projects/{project_id}/sync¶
Read the project's web and S3 documents again and index what changed.
- Unchanged pages and objects stay as they are (
unchanged). - A changed one gets a new version, chunked with the options of the version it replaces. The old version is then deleted.
- A gone one (HTTP 404 or 410, or no such key) is
missing, ordeletedwithdelete_missing. - New pages or objects are not discovered. Import the site or prefix again for that.
Body (JSON, unknown fields refused):
| Field | Type | Default | |
|---|---|---|---|
document_ids |
list of integers, 1 to 10000 | every web and S3 document | Only these documents |
delete_missing |
boolean | false |
Delete documents whose page or object is gone |
background |
boolean | false |
Return at once and sync as a job |
Response: 200 with the upload response.
Its stats has checked, the number of documents checked.