---
title: "Add a document (file, URL, or text)"
method: POST
path: "/v1/knowledgebases/{id}/documents"
tags: ["Knowledge Bases"]
---

# Add a document (file, URL, or text)

`POST /v1/knowledgebases/{id}/documents`

## Request

- Base URL: `https://api.pyai.com`
- URL: `https://api.pyai.com/v1/knowledgebases/{id}/documents`
- Auth: one of:
  - HTTP bearer
  - API key in header `x-api-key`

Three ways to add content: a multipart file upload (pdf, docx, xlsx, txt, md, csv, html, json; 25MB max), a JSON `{ "url" }` to fetch and parse, or a JSON `{ "text" }` to paste content directly. The document registers as `pending` and is chunked + embedded asynchronously; poll its `status` until `indexed`. Requires the `kb:manage` scope.

## Path parameters

- `id` string, required

## Request body

- object
  - `url` string, uri
  - `text` string
  - `title` string

## Response `202`

Document registered (pending ingestion)

- KbDocument: A knowledge base document and its ingestion state.
  - `id` string
  - `kbId` string
  - `orgId` string
  - `source` 'upload' | 'url' | 'api': upload = file, url = fetched page, api = pasted text.
  - `uri` string, nullable
  - `title` string, nullable
  - `filename` string, nullable
  - `mime` string, nullable
  - `sizeBytes` integer
  - `chunks` integer: Indexed chunk count (0 until indexed).
  - `status` 'pending' | 'indexed' | 'failed'
  - `error` string, nullable: Human-readable failure/stall reason.
  - `indexedAt` integer, nullable: Unix ms.
  - `createdAt` integer: Unix ms.

## Other responses

- `400`: Invalid request (bad field, unsupported value)
- `404`: Resource not found (`code: not_found`)
- `413`: File exceeds the 25MB limit.
- `415`: Unsupported document type.

---

[API](https://skmtc.dev/pyai/apis/pyai-api.md) · [All operations](https://skmtc.dev/pyai/apis/pyai-api/llms.txt) · [OpenAPI document](https://skmtc.dev/pyai/apis/pyai-api/revisions/271a1539185b?raw)
