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

# Upload documents to a knowledge base

> Uploads one or more files to a knowledge base for chunking and embedding. Documents are processed asynchronously. Listen for the knowledgedocument.finished webhook or poll the document endpoint to know when they are searchable.



## OpenAPI

````yaml /openapi.json post /api/v1/knowledge-bases/{slug}/documents
openapi: 3.1.1
info:
  title: PromptJuggler
  description: PromptJuggler API
  version: 1.0.0
servers:
  - url: https://promptjuggler.com
security:
  - Bearer: []
tags:
  - name: Prompts
    description: Fetch prompts and revisions.
  - name: Prompt Runs
    description: Execute published prompts and retrieve results.
  - name: Workflow Runs
    description: Execute multi-step workflows and retrieve results.
  - name: Knowledge Bases
    description: Upload and manage documents used for retrieval-augmented generation.
paths:
  /api/v1/knowledge-bases/{slug}/documents:
    post:
      tags:
        - Knowledge Bases
      summary: Upload documents to a knowledge base
      description: >-
        Uploads one or more files to a knowledge base for chunking and
        embedding. Documents are processed asynchronously. Listen for the
        knowledgedocument.finished webhook or poll the document endpoint to know
        when they are searchable.
      operationId: public_upload_documents
      parameters:
        - name: slug
          in: path
          description: Knowledge base handle
          required: true
          schema:
            type: string
      requestBody:
        content:
          multipart/form-data:
            schema:
              properties:
                files:
                  type: array
                  items:
                    type: string
                    format: binary
              type: object
      responses:
        '200':
          description: Documents created
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/KnowledgeDocumentResponse'
        '401':
          description: Missing or invalid API key
        '403':
          description: No active subscription
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Knowledge base not found
        '422':
          description: Invalid file (unsupported MIME type or too large)
      x-codeSamples:
        - lang: PHP
          label: PromptJuggler PHP SDK
          source: >-
            $docs = $pj->uploadDocuments('product-docs', ['manual.pdf' =>
            file_get_contents('manual.pdf')]);
        - lang: TypeScript
          label: PromptJuggler TypeScript SDK
          source: >-
            const docs = await pj.uploadDocuments('product-docs', [new
            File([await readFile('manual.pdf')], 'manual.pdf')]);
        - lang: Python
          label: PromptJuggler Python SDK
          source: >-
            docs = pj.upload_documents('product-docs', [('manual.pdf',
            open('manual.pdf', 'rb').read())])
        - lang: Java
          label: PromptJuggler Java SDK
          source: >-
            List<KnowledgeDocumentResponse> docs =
            pj.uploadDocuments("product-docs", List.of(new File("manual.pdf")));
        - lang: Go
          label: PromptJuggler Go SDK
          source: docs, err := pj.UploadDocuments(ctx, "product-docs", file)
components:
  schemas:
    KnowledgeDocumentResponse:
      description: Knowledge document
      required:
        - id
        - status
        - fileName
        - bytes
        - chunkCount
      properties:
        id:
          description: Document ID
          type: string
          format: uuid
        status:
          $ref: '#/components/schemas/KnowledgeDocumentStatus'
          description: Processing status
        fileName:
          description: Original file name
          type: string
        bytes:
          description: File size in bytes
          type: integer
        chunkCount:
          description: Number of chunks extracted
          type: integer
      type: object
    ErrorResponse:
      description: Error response.
      required:
        - error
      properties:
        error:
          description: Error message.
          type: string
      type: object
    KnowledgeDocumentStatus:
      type: string
      enum:
        - pending
        - sealed
        - ready
        - failed
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

````