> ## 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 or TXT file for agent retrieval.

<span data-api-safety-label="changes-state"><Badge color="yellow" size="sm" shape="pill">Changes state - verify before retry</Badge></span>

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

## Before you begin

* [Create a knowledge base](/docs/api-reference/v1/knowledge-base/create) and keep its `kb_` ID.
* Prepare a PDF or TXT file no larger than 100 MB (104857600 bytes).
* Choose a non-empty title unique within that knowledge base. Each knowledge base allows 25 non-deleted documents.

## 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. Let your HTTP client set the multipart boundary.

## Verify the result

A `201` response contains the created document in `data`, including its ID, title, knowledge base ID, file type, and size. [List Knowledge Base Documents](/docs/api-reference/v1/knowledge-base/documents) and confirm the file is present. 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 format, and the 25-document limit.                |
| `401`  | Correct the API key.                                                             |
| `404`  | Select a knowledge base in this workspace.                                       |
| `409`  | A document with the same title exists. Inspect it before choosing another title. |
| `413`  | Reduce the file below the 100 MB limit.                                          |
| `500`  | Parsing, storage, or indexing failed. Inspect the document list before retrying. |

Uploading stores a file and indexes its content. 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](/docs/knowledge-base/managing-documents).

## Related endpoints

* [List Knowledge Base Documents](/docs/api-reference/v1/knowledge-base/documents)
* [Knowledge base file limits](/docs/knowledge-base/documents-and-file-limits)


## 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: Transcribers
  - name: Webhooks
  - name: Voices
  - name: Workflows
  - name: Workflow Leads
  - name: Authentication
  - name: Agent Builder
paths:
  /v1/documents/upload:
    post:
      tags:
        - Knowledge Base
      summary: Upload Knowledge Base Document
      description: >-
        Parses, stores, and indexes one PDF or TXT document in a knowledge base
        owned by the authenticated workspace. Maximum 100 MB per document and 25
        non-deleted documents per knowledge base. Document 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 or TXT file, at most 100 MB (104857600 bytes).
                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: abc123def45678
                      title: Support FAQ
                      knowledge_base_id: abc123def45678
                      document_type: txt
                      file_size: 1
                      is_deleted: false
                    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
                    message: >-
                      Missing fields, unsupported file, or document count limit
                      reached.
                    error: Bad Request
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 401
                    message: Missing or invalid API key.
                    error: Unauthorized
        '404':
          description: Knowledge base not found in this workspace.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 404
                    message: Knowledge base not found in this workspace.
                    error: Not Found
        '409':
          description: A document with this title already exists.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 409
                    message: A document with this title already exists.
                    error: Conflict
        '413':
          description: File exceeds the 100 MB upload limit.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 413
                    message: File exceeds the 100 MB upload limit.
                    error: Payload Too Large
        '500':
          description: Document parsing, storage, or indexing failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                error:
                  value:
                    statusCode: 500
                    message: Document parsing, storage, or indexing failed.
                    error: Internal Server Error
      security:
        - bearer: []
components:
  schemas:
    KnowledgeBaseDocument:
      type: object
      properties:
        id:
          type: string
        title:
          type: string
        knowledge_base_id:
          type: string
        description:
          type: string
        content:
          type: string
        source:
          type: string
        document_type:
          type: string
        file_path:
          type: string
        file_size:
          type: number
          description: File size in KB (1024 bytes).
        is_deleted:
          type: boolean
    ErrorResponse:
      type: object
      properties:
        statusCode:
          type: integer
          example: 400
        message:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          example: phone_number must be a valid E.164 phone number
        error:
          type: string
          example: Bad Request
      required:
        - statusCode
        - message
        - error
  securitySchemes:
    bearer:
      scheme: bearer
      type: http

````