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

# Add Document

> Add a document to a knowledge base using JSON text or multipart file upload.



## OpenAPI

````yaml https://registry.scalar.com/@profound/apis/external-api/latest/openapi.json?variant=processed post /v1/knowledge-bases/{knowledge_base_id}/documents
openapi: 3.1.0
info:
  title: External API
  version: 0.60.2
  x-scalar-sdk-installation:
    - lang: Python
      description: |-
        ```sh
        pip install profound
        ```
    - lang: TypeScript
      description: |-
        ```sh
        npm install @profoundai/client
        ```
    - lang: Rust
      description: |-
        ```sh
        cargo add profound
        ```
servers:
  - url: https://api.tryprofound.com
    description: Production Server
security:
  - APIKeyHeader:
      - X-API-Key
  - BearerAuth: []
paths:
  /v1/knowledge-bases/{knowledge_base_id}/documents:
    post:
      tags:
        - Knowledge bases
      summary: Add Document
      description: >-
        Add a document to a knowledge base using JSON text or multipart file
        upload.
      operationId: add_document_v1_knowledge_bases__knowledge_base_id__documents_post
      parameters:
        - name: knowledge_base_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            description: Unique knowledge base ID.
            title: Knowledge Base Id
          description: Unique knowledge base ID.
        - name: organization_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                format: uuid
              - type: 'null'
            description: >-
              Organization scope for API keys that can access multiple
              organizations.
            title: Organization Id
          description: >-
            Organization scope for API keys that can access multiple
            organizations.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              additionalProperties: false
              properties:
                name:
                  description: Unique document name.
                  minLength: 1
                  title: Name
                  type: string
                text:
                  description: Text content to add to the document.
                  minLength: 1
                  title: Text
                  type: string
                folder:
                  anyOf:
                    - type: string
                      minLength: 1
                    - type: 'null'
                  description: Folder path to add the document under.
                  title: Folder
              required:
                - name
                - text
              title: AddDocumentRequest
              type: object
          multipart/form-data:
            schema:
              type: object
              required:
                - name
                - file
              properties:
                name:
                  type: string
                  description: Document name or path.
                folder:
                  type: string
                  description: Folder path containing the document.
                file:
                  type: string
                  format: binary
                  description: Document file to upload.
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocumentOperationResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
        - BearerAuth: []
      x-codeSamples:
        - label: Python
          lang: Python
          source: |-
            import os

            from profound import Profound

            client = Profound(
                api_key=os.environ.get("PROFOUND_API_KEY"),
            )

            document = client.knowledge_bases.documents.create(
                knowledge_base_id="7c9e6679-7425-40de-944b-e07fc1f90ae7",
                name="x",
                text="x",
            )

            print(document)
        - label: TypeScript
          lang: TypeScript
          source: >-
            import Profound from '@profoundai/client';


            const client = new Profound({
              apiKey: process.env['PROFOUND_API_KEY'], // defaults to the PROFOUND_API_KEY env var
              environment: 'production',
            });


            const document = await
            client.knowledgeBases.documents.create('7c9e6679-7425-40de-944b-e07fc1f90ae7',
            {
              name: 'x',
              text: 'x',
            });


            console.log(document);
        - label: rust
          lang: rust
          source: |-
            use profound::*;

            #[tokio::main]
            async fn main() -> Result<(), Box<dyn std::error::Error>> {
                let client = ProfoundClient::builder()
                    .api_key(std::env::var("PROFOUND_API_KEY")?)
                    .build()?;

                let response = client
                    .knowledge_bases()
                    .documents()
                    .create(
                        "7c9e6679-7425-40de-944b-e07fc1f90ae7",
                        DocumentsCreateBody {
                            name: "x".to_string(),
                            text: "x".to_string(),
                            folder: None,
                        },
                    )
                    .send()
                    .await?;

                println!("{:?}", response);

                Ok(())
            }
components:
  schemas:
    DocumentOperationResponse:
      properties:
        message:
          type: string
          title: Message
          description: Operation result message.
        name:
          type: string
          title: Name
          description: Document name.
        path:
          type: string
          title: Path
          description: Document path.
        folder:
          anyOf:
            - type: string
            - type: 'null'
          title: Folder
          description: Document folder path.
      additionalProperties: false
      type: object
      required:
        - message
        - name
        - path
      title: DocumentOperationResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````