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

# Upload knowledge document

> Upload PDF, Word, Excel, or TXT (requires knowledge:write scope).

Requires scope **`knowledge:write`**.

* **Multipart** field name: `file`
* **Types:** PDF, DOC/DOCX, XLS/XLSX/XLSM, TXT
* **Max size:** 50MB

**Live keys:** credits may be debited when KB billing is enabled (`402 insufficient_credits` if balance too low).

**Sandbox keys:** upload succeeds without debiting credits; response includes `billing.sandbox: true`.

There is **no** v1 download endpoint — binary access stays dashboard/session only.


## OpenAPI

````yaml openapi.json POST /api/v1/knowledge-bases/documents
openapi: 3.0.3
info:
  title: Ondial Public API
  version: 1.0.0
  description: >-
    Tenant API-key surface for lead ingest, contacts (including dial
    conversation + analysis), events, inbound agents, company profiles, and
    knowledge-base documents.


    **Campaign definition is UI-only** — create and start an API-ingest campaign
    in the dashboard, then push leads here.


    **Auth:** `Authorization: Bearer ond_live_…` or `ond_test_…` (or
    `X-API-Key`). Keys are requested in **API Access** with a friendly **key
    name**, then approved by Super Admin (not self-serve). Tenants can rename
    keys later without rotating the secret.


    **Scopes:** Company and knowledge-base routes require opt-in scopes
    (`companies:read`, `companies:write`, `knowledge:read`, `knowledge:write`)
    granted at key approval. Missing scope → `403 forbidden`.


    **Sandbox** keys never place PSTN dials or live WhatsApp/email and do not
    burn credits (KB upload skips debit).


    **Security:** Company responses never include SMTP/WhatsApp credentials. KB
    v1 is metadata-only — no file download.


    **Kill switch:** Super Admin can disable all `/api/v1/*` (`503` /
    `api_globally_disabled`) without stopping UI CSV campaigns.


    **Compliance:** Call channel requires `consent.outboundCall: true` and phone
    not on tenant/platform DNC.
servers:
  - url: https://dashboard.ondial.ai
    description: Production
  - url: http://localhost:3001
    description: Local
security:
  - BearerAuth: []
tags:
  - name: Core
    description: Auth check and lead ingest
  - name: Contacts
    description: Status, dials/conversation/analysis, cancel, delete, follow-ups, list
  - name: Events
    description: ERP event bus slice — eventType → campaign
  - name: Outbound
    description: >-
      Read-only campaign lookup for API / Custom CRM. Create and start campaigns
      in the dashboard.
  - name: Inbound agents
    description: Configure inbound agents; list/buy pool numbers; read credits
  - name: Companies
    description: >-
      Company profile CRUD (requires companies:read / companies:write scopes).
      Never returns SMTP or WhatsApp credentials.
  - name: Knowledge bases
    description: >-
      Knowledge document upload/list/delete (requires knowledge:read /
      knowledge:write scopes). Metadata only — no file download via API.
paths:
  /api/v1/knowledge-bases/documents:
    post:
      tags:
        - Knowledge bases
      summary: Upload knowledge document
      description: >-
        Multipart upload (field `file`). PDF, Word, Excel, or TXT — max 50MB.
        Requires scope `knowledge:write`. Live keys debit credits when billing
        is enabled; sandbox keys skip debit.
      operationId: uploadKnowledgeDocument
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
      responses:
        '201':
          description: Uploaded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KnowledgeUploadResponse'
        '400':
          description: invalid_request / invalid_file_type / file_too_large
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: insufficient_credits
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
              example:
                error: Insufficient credits for knowledge upload
                reasonCode: insufficient_credits
                requiredCredits: 1.5
                creditsAvailable: 0.25
components:
  schemas:
    KnowledgeUploadResponse:
      type: object
      properties:
        document:
          $ref: '#/components/schemas/KnowledgeDocument'
        billing:
          type: object
          properties:
            knowledgeBaseCreditsEnabled:
              type: boolean
            sandbox:
              type: boolean
            creditsDeducted:
              type: number
            creditsRemaining:
              type: number
            wordCount:
              type: integer
            charCount:
              type: integer
    ErrorBody:
      type: object
      properties:
        error:
          type: string
        reasonCode:
          type: string
        missing:
          type: array
          items:
            type: string
    KnowledgeDocument:
      type: object
      properties:
        fileId:
          type: string
        knowledgebaseId:
          type: string
          nullable: true
        fileName:
          type: string
          nullable: true
        title:
          type: string
          nullable: true
        wordCount:
          type: integer
        uploadDate:
          type: string
          format: date-time
          nullable: true
        fileType:
          type: string
          enum:
            - pdf
            - word
            - excel
            - text
      description: Metadata only. No download URL or file bytes.
  responses:
    Unauthorized:
      description: Missing, invalid, or inactive API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            error: Invalid or inactive API key
            reasonCode: unauthorized
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: ond_live | ond_test
      description: >-
        Paste only your API key (`ond_live_…` or `ond_test_…`). Do not type the
        word Bearer — the playground adds it.

````