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

# Upload Knowledge Base Document

> Upload a knowledge base document to store and index a PDF, TXT, or DOCX file for agent retrieval.

Changes state - verify before retry

Upload a knowledge base document to store and index a PDF, TXT, or DOCX file for agent retrieval. The knowledge base must already exist in the authenticated workspace and must not have been deleted.

## Before you begin

* [Create a knowledge base](https://dialnexa.com/docs/api-reference/v1/knowledge-base/create.md) and keep its `kb_` ID.
* Prepare a PDF, TXT, or DOCX file no larger than 20 MB (20971520 bytes). Legacy binary `.doc` files are not accepted. A file over the limit returns `400`, and one well over it is refused with `413` before the request is processed. The text extracted from the file must also stay under 20 MB, or the upload returns `400`.
* Choose a non-empty title unique within that knowledge base; a duplicate title returns `409 Conflict`. Each knowledge base allows 25 documents; the 26th upload returns `400`.

## Upload Knowledge Base Document Request

```bash theme={null}
curl https://api.dialnexa.com/v1/documents/upload \
  -H "Authorization: Bearer $DIALNEXA_API_KEY" \
  -F "knowledge_base_id=kb_abc123" \
  -F "title=Support FAQ" \
  -F "file=@support-faq.txt;type=text/plain"
```

Optional `description` and `source` fields describe the file. The file name must end in `.pdf`, `.txt` or `.docx`, and the file part's `Content-Type` must be `application/pdf`, `text/plain` or `application/vnd.openxmlformats-officedocument.wordprocessingml.document`; a part sent as `application/octet-stream` returns `400`. Let your HTTP client set the multipart boundary.

## Verify the result

A `201` response contains the created document in `data`: its `id`, `title`, `knowledge_base_id` (raw, without `kb_`), `document_type`, `file_size` in KB, `file_path`, the extracted text in `content`, and its indexing state. `ingest_status` is `ready` when indexing finished during the request and `processing` when it is still running; in that case, call [List Knowledge Base Documents](https://dialnexa.com/docs/api-reference/v1/knowledge-base/documents.md) and poll until it is `ready`. If indexing cannot be started at all, the upload fails with `500` and the document is not kept. If a started job fails later, the document is removed from the list (it is marked deleted with `ingest_status` `failed`), so a document that disappears while you poll has failed; correct the file and upload it again with the same title. Attach the knowledge base to the intended agent and ask a test question covered by the document.

## Errors and recovery

| Status | Recovery |
| - | - |
| `400` | Check required fields, PDF/TXT/DOCX format, and the 25-document limit. |
| `401` | Correct the API key. |
| `404` | Select a knowledge base in this workspace that has not been deleted. |
| `409` | The title already exists, or the knowledge base is indexing. Inspect the list and wait for active processing before retrying. |
| `413` | Reduce the file below the 20 MB limit. |
| `500` | Parsing, storage, or indexing failed. Inspect the document list before retrying. |

Uploading stores a file and starts background indexing. It is not an idempotent replacement operation. After an uncertain response, list documents before retrying; changing the title can create duplicate content. To replace an existing document, use [dashboard document management](https://dialnexa.com/docs/knowledge-base/managing-documents.md).

## Related endpoints

* [List Knowledge Base Documents](https://dialnexa.com/docs/api-reference/v1/knowledge-base/documents.md)
* [Knowledge base file limits](https://dialnexa.com/docs/knowledge-base/documents-and-file-limits.md)


## OpenAPI

````yaml POST /v1/documents/upload
openapi: 3.0.0
info:
  title: DialNexa API
  description: Public `/v1` REST API for the DialNexa voice AI platform.
  version: 1.0.0
servers:
  - url: https://api.dialnexa.com
    description: DialNexa production API
security:
  - bearer: []
tags:
  - name: Agents
  - name: Batch Calls
  - name: Calls
  - name: Knowledge Base
  - name: Languages
  - name: LLMs
  - name: Phone Numbers
  - name: Organization Folders
  - name: Transcribers
  - name: Webhooks
  - name: Voices
  - name: Workflows
  - name: Workflow Leads
  - name: Authentication
  - name: Agent Builder
  - name: Agent Evaluations
paths:
  /v1/documents/upload:
    post:
      tags:
        - Knowledge Base
      summary: Upload Knowledge Base Document
      description: >-
        Stores one PDF, TXT, or DOCX document and starts background indexing.
        Maximum 20 MB per file and 20 MB extracted text, with 25 non-deleted
        documents per knowledge base. A 201 response means accepted, not ready
        for retrieval. Poll List Knowledge Base Documents until ingest_status is
        ready. Titles must be unique within the knowledge base.
      operationId: uploadKnowledgeBaseDocument
      parameters: []
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                  description: >-
                    PDF, TXT, or DOCX file, at most 20 MB (20971520 bytes).
                    Legacy DOC files are not supported.
                title:
                  type: string
                  minLength: 1
                knowledge_base_id:
                  type: string
                description:
                  type: string
                source:
                  type: string
              required:
                - file
                - title
                - knowledge_base_id
            examples:
              request:
                value:
                  file: support-faq.txt
                  title: Support FAQ
                  knowledge_base_id: kb_abc123def45678
      responses:
        '201':
          description: Successful response.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  error:
                    type: boolean
                  statusCode:
                    type: integer
                  message:
                    type: string
                  data:
                    $ref: '#/components/schemas/KnowledgeBaseDocument'
                  timestamp:
                    type: string
                    format: date-time
                required:
                  - success
                  - error
                  - statusCode
                  - message
                  - data
                  - timestamp
              examples:
                success:
                  value:
                    success: true
                    error: false
                    statusCode: 201
                    message: Success
                    data:
                      id: Dk4mP8vQ2nLz7x
                      title: Support FAQ
                      knowledge_base_id: abc123def45678
                      description: ''
                      content: >-
                        How do I reset my password? Open Settings and choose
                        Reset password.
                      source: ''
                      document_type: txt
                      file_size: 0.0664
                      file_path: >-
                        knowledge-documents/abc123def45678/Support_FAQ-Dk4mP8vQ2nLz7x.txt
                      is_deleted: false
                      ingest_status: processing
                      ingest_error: null
                      ingest_updated_at: '2026-07-03T10:30:00.000Z'
                      ingest_job_id: 3f6c2a9e-8b1d-4e7a-9c5f-2d8e1b7a4c63
                    timestamp: '2026-09-07T06:00:00.000Z'
        '400':
          description: Missing fields, unsupported file, or document count limit reached.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 400
                    error: true
                    success: false
                    data: []
                    message: >-
                      Maximum limit of 25 documents reached for knowledge base
                      ID Qm4TzR8wLp2VxN
                    errors: []
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 401
                    error: true
                    success: false
                    data: []
                    message: Invalid API key
                    errors: []
        '404':
          description: Knowledge base not found in this workspace, or it has been deleted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 404
                    error: true
                    success: false
                    data: []
                    message: Knowledge base with ID Qm4TzR8wLp2VxN not found
                    errors: []
        '409':
          description: >-
            A document with this title already exists, or the knowledge base is
            currently indexing.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 409
                    error: true
                    success: false
                    data: []
                    message: >-
                      A document named "Pricing FAQ" already exists in this
                      knowledge base
                    errors: []
        '413':
          description: >-
            File exceeds 21 MB and is rejected by the upload interceptor before
            the handler runs. A file between 20 MB and 21 MB gets a 400 instead.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 413
                    error: true
                    success: false
                    data: []
                    message: File too large
                    errors: []
        '500':
          description: Document parsing, storage, or indexing failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 500
                    error: true
                    success: false
                    data: []
                    message: >-
                      Could not start indexing for this document. Please try
                      again.
                    errors: []
      security:
        - bearer: []
components:
  schemas:
    KnowledgeBaseDocument:
      type: object
      properties:
        id:
          type: string
          description: Document ID (raw, no prefix).
        title:
          type: string
        knowledge_base_id:
          type: string
          description: Knowledge base ID without the kb_ prefix.
        description:
          type: string
        content:
          type: string
          description: Full text extracted from the file.
        source:
          type: string
        document_type:
          type: string
        file_path:
          type: string
          description: Storage path of the uploaded file.
        file_size:
          type: number
          description: File size in KB (1024 bytes).
        is_deleted:
          type: boolean
        ingest_status:
          type: string
          enum:
            - processing
            - ready
            - failed
          description: >-
            Indexing state: processing until indexing finishes, then ready. A
            document whose indexing fails is marked failed with ingest_error set
            and deleted at the same time, so it leaves the document list and can
            be uploaded again under the same title.
        ingest_error:
          type: string
          nullable: true
        ingest_updated_at:
          type: string
          format: date-time
          nullable: true
        ingest_job_id:
          type: string
          nullable: true
          description: Identifier of the current indexing attempt.
    ErrorResponse:
      type: object
      description: Error body on endpoints without response filtering.
      properties:
        statusCode:
          type: integer
          example: 404
        error:
          type: boolean
          enum:
            - true
        success:
          type: boolean
          enum:
            - false
        data:
          oneOf:
            - type: object
              properties:
                code:
                  type: string
                  description: Machine-readable refusal code.
            - type: array
              items: {}
          description: >-
            For a coded refusal, an object with code and the details listed for
            that code. Otherwise an empty array.
        message:
          type: string
        errors:
          type: array
          items:
            type: string
          description: Validation messages for a 400. Empty for other errors.
        validation_errors:
          type: array
          description: >-
            Present when uploaded rows fail number validation (batch and
            workflow lead uploads): one group per distinct error.
          items:
            type: object
            properties:
              error:
                type: string
              rows:
                type: array
                items:
                  type: integer
                description: Row numbers with this error.
              phone_numbers:
                type: array
                items:
                  type: string
        invalid_row_count:
          type: integer
          description: 'Present with validation_errors: how many rows failed.'
      required:
        - statusCode
        - error
        - success
        - data
        - message
        - errors
  securitySchemes:
    bearer:
      scheme: bearer
      type: http

````

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