> ## Documentation Index
> Fetch the complete documentation index at: https://docs.autocalls.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

<ParamField path="knowledgebaseId" type="integer" required>
  The unique identifier of the knowledgebase
</ParamField>

### Request Body

<ParamField body="name" type="string" required>
  The name of the document (max 255 characters)
</ParamField>

<ParamField body="description" type="string">
  Optional description of the document (max 255 characters)
</ParamField>

<ParamField body="type" type="string" required>
  Document type: `website`, `pdf`, `txt`, or `docx`
</ParamField>

#### Website Documents

<ParamField body="url" type="string">
  The main URL to scrape. Required if `links` is not provided.
</ParamField>

<ParamField body="links" type="array">
  Array of specific URLs to scrape. Required if `url` is not provided.

  <Expandable title="links properties">
    <ParamField body="link" type="string" required>
      A valid URL to include in the document
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="relative_links_limit" type="integer" default="10">
  Maximum number of relative links to follow when scraping (1-50)
</ParamField>

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

<ParamField body="file" type="file" required>
  The file to upload (max 20MB). Use `multipart/form-data` encoding.
</ParamField>

### Response

<ResponseField name="message" type="string">
  Success message
</ResponseField>

<ResponseField name="data" type="object">
  The created document object

  <Expandable title="data properties">
    <ResponseField name="id" type="integer">
      The unique identifier of the document
    </ResponseField>

    <ResponseField name="name" type="string">
      The name of the document
    </ResponseField>

    <ResponseField name="description" type="string">
      Description of the document
    </ResponseField>

    <ResponseField name="type" type="string">
      Document type
    </ResponseField>

    <ResponseField name="type_label" type="string">
      Human-readable type label
    </ResponseField>

    <ResponseField name="status" type="string">
      Processing status (will be `processing` initially)
    </ResponseField>

    <ResponseField name="status_label" type="string">
      Human-readable status label
    </ResponseField>

    <ResponseField name="created_at" type="string">
      ISO 8601 timestamp of creation
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```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."
  }
  ```
</ResponseExample>

### 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.autocalls.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.autocalls.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](/api-reference/knowledgebases/get-document) endpoint to check when processing is complete.
</Note>
