> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lacy.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create document

> Add a new document to a knowledgebase

This endpoint creates a new document in a knowledgebase. Documents are processed asynchronously - the endpoint returns immediately while processing continues in the background.

### Path Parameters

**knowledgebaseId** `integer` *required*

The unique identifier of the knowledgebase

### Request Body

**name** `string` *required*

The name of the document (max 255 characters)

**description** `string`

Optional description of the document (max 255 characters)

**type** `string` *required*

Document type: `website`, `pdf`, `txt`, or `docx`

#### Website Documents

**url** `string`

The main URL to scrape. Required if `links` is not provided.

**links** `array`

Array of specific URLs to scrape. Required if `url` is not provided.

**links properties**

**link** `string` *required*

A valid URL to include in the document

**relative\_links\_limit** `integer` (default: 10)

Maximum number of relative links to follow when scraping (1-50)

#### File Documents (PDF, TXT, DOCX)

**file** `file` *required*

The file to upload (max 20MB). Use `multipart/form-data` encoding.

### Response

**message** `string`

Success message

**data** `object`

The created document object

**data properties**

**id** `integer`

The unique identifier of the document

**name** `string`

The name of the document

**description** `string`

Description of the document

**type** `string`

Document type

**type\_label** `string`

Human-readable type label

**status** `string`

Processing status (will be `processing` initially)

**status\_label** `string`

Human-readable status label

**created\_at** `string`

ISO 8601 timestamp of creation

```json 201 Website Document Created theme={null}
{
  "message": "Document created successfully. Processing will begin shortly.",
  "data": {
    "id": 1,
    "name": "Company Website",
    "description": "Main website content",
    "type": "website",
    "type_label": "Website",
    "status": "processing",
    "status_label": "Processing",
    "created_at": "2025-01-08T10:30:00.000000Z"
  }
}
```

```json 201 PDF Document Created theme={null}
{
  "message": "Document created successfully. Processing will begin shortly.",
  "data": {
    "id": 2,
    "name": "Product Manual",
    "description": "User guide for our product",
    "type": "pdf",
    "type_label": "PDF",
    "status": "processing",
    "status_label": "Processing",
    "created_at": "2025-01-08T10:35:00.000000Z"
  }
}
```

```json 404 Knowledgebase Not Found theme={null}
{
  "error": "Knowledgebase not found."
}
```

```json 422 Validation Error theme={null}
{
  "message": "A file is required for this document type.",
  "errors": {
    "file": [
      "A file is required for this document type."
    ]
  }
}
```

```json 500 Processing Error theme={null}
{
  "error": "Failed to create document. Please try again."
}
```

### Document Types

| Type | Description | Input |
| - | - | - |
| `website` | Scrapes web pages and extracts text content | URL or list of URLs |
| `pdf` | Extracts text from PDF files | PDF file upload |
| `txt` | Plain text content | TXT file upload |
| `docx` | Extracts text from Word documents | DOCX file upload |

### Example: Creating a Website Document

```bash theme={null}
curl -X POST https://app.lacy.ai/api/user/knowledgebases/1/documents \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Company Website",
    "description": "Main website content",
    "type": "website",
    "url": "https://example.com",
    "relative_links_limit": 20
  }'
```

### Example: Uploading a PDF Document

```bash theme={null}
curl -X POST https://app.lacy.ai/api/user/knowledgebases/1/documents \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "name=Product Manual" \
  -F "description=User guide for our product" \
  -F "type=pdf" \
  -F "file=@/path/to/document.pdf"
```

> [!NOTE]
>
> Document processing is asynchronous. Poll the [get document](https://docs.lacy.ai/api-reference/knowledgebases/get-document.md) endpoint to check when processing is complete.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.