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

# Create Document by File

> Create a document by uploading a file. Supports common document formats (PDF, TXT, DOCX, etc.). Processing is asynchronous — use the returned `batch` ID with [Get Document Indexing Status](/api-reference/documents/get-document-indexing-status) to track progress.



## OpenAPI

````yaml /en/api-reference/openapi_knowledge.json post /datasets/{dataset_id}/document/create-by-file
openapi: 3.0.1
info:
  title: Knowledge API
  description: >-
    API for managing knowledge bases, documents, chunks, metadata, and tags,
    including creation, retrieval, and configuration. **Note:** A single
    Knowledge Base API key has permission to operate on all visible knowledge
    bases under the same account. Please pay attention to data security.
  version: 1.0.0
servers:
  - url: '{apiBaseUrl}'
    description: The base URL for the Knowledge API.
    variables:
      apiBaseUrl:
        default: https://api.dify.ai/v1
        description: Actual base URL of the API
security:
  - ApiKeyAuth: []
tags:
  - name: Knowledge Bases
    description: >-
      Operations for managing knowledge bases, including creation,
      configuration, and retrieval.
  - name: Documents
    description: >-
      Operations for creating, updating, and managing documents within a
      knowledge base.
  - name: Chunks
    description: Operations for managing document chunks and child chunks.
  - name: Metadata
    description: >-
      Operations for managing knowledge base metadata fields and document
      metadata values.
  - name: Tags
    description: Operations for managing knowledge base tags and tag bindings.
  - name: Models
    description: Operations for retrieving available models.
  - name: Knowledge Pipeline
    description: >-
      Operations for managing and running knowledge pipelines, including
      datasource plugins and pipeline execution.
paths:
  /datasets/{dataset_id}/document/create-by-file:
    post:
      tags:
        - Documents
      summary: Create Document by File
      description: >-
        Create a document by uploading a file. Supports common document formats
        (PDF, TXT, DOCX, etc.). Processing is asynchronous — use the returned
        `batch` ID with [Get Document Indexing
        Status](/api-reference/documents/get-document-indexing-status) to track
        progress.
      operationId: createDocumentFromFile
      parameters:
        - name: dataset_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: Knowledge base ID.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
                  description: File to upload.
                data:
                  type: string
                  description: >-
                    JSON string containing configuration. Accepts the same
                    fields as [Create Document by
                    Text](/api-reference/documents/create-document-by-text)
                    (`indexing_technique`, `doc_form`, `doc_language`,
                    `process_rule`, `retrieval_model`, `embedding_model`,
                    `embedding_model_provider`) except `name` and `text`.
                  example: >-
                    {"indexing_technique":"high_quality","doc_form":"text_model","doc_language":"English","process_rule":{"mode":"automatic"}}
      responses:
        '200':
          description: Document created successfully.
          content:
            application/json:
              schema:
                type: object
                properties:
                  document:
                    $ref: '#/components/schemas/Document'
                  batch:
                    type: string
                    description: Batch ID for tracking indexing progress.
              examples:
                success:
                  summary: Response Example
                  value:
                    document:
                      id: a8e0e5b5-78c6-4130-a5ce-25feb0e0b4ac
                      position: 1
                      data_source_type: upload_file
                      data_source_info:
                        upload_file_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                      data_source_detail_dict:
                        upload_file:
                          id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                          name: guide.txt
                          size: 2048
                          extension: txt
                          mime_type: text/plain
                          created_by: ad313dd6-ef04-4dd1-a5b0-c0f0b9e2e7e4
                          created_at: 1741267200
                      dataset_process_rule_id: e1f2a3b4-c5d6-7890-ef12-345678901234
                      name: guide.txt
                      created_from: api
                      created_by: ad313dd6-ef04-4dd1-a5b0-c0f0b9e2e7e4
                      created_at: 1741267200
                      tokens: 0
                      indexing_status: indexing
                      error: null
                      enabled: true
                      disabled_at: null
                      disabled_by: null
                      archived: false
                      display_status: indexing
                      word_count: 0
                      hit_count: 0
                      doc_form: text_model
                      doc_metadata: []
                      summary_index_status: null
                      need_summary: false
                    batch: '20250306150245647595'
        '400':
          description: >-
            - `no_file_uploaded` : Please upload your file.

            - `too_many_files` : Only one file is allowed.

            - `filename_not_exists_error` : The specified filename does not
            exist.

            - `provider_not_initialize` : No valid model provider credentials
            found. Please go to Settings -> Model Provider to complete your
            provider credentials.

            - `invalid_param` : Knowledge base does not exist, external datasets
            not supported, file too large, unsupported file type, missing
            required fields, or invalid doc_form (must be `text_model`,
            `hierarchical_model`, or `qa_model`).
          content:
            application/json:
              examples:
                no_file_uploaded:
                  summary: no_file_uploaded
                  value:
                    status: 400
                    code: no_file_uploaded
                    message: Please upload your file.
                too_many_files:
                  summary: too_many_files
                  value:
                    status: 400
                    code: too_many_files
                    message: Only one file is allowed.
                filename_not_exists_error:
                  summary: filename_not_exists_error
                  value:
                    status: 400
                    code: filename_not_exists_error
                    message: The specified filename does not exist.
                provider_not_initialize:
                  summary: provider_not_initialize
                  value:
                    status: 400
                    code: provider_not_initialize
                    message: >-
                      No valid model provider credentials found. Please go to
                      Settings -> Model Provider to complete your provider
                      credentials.
                invalid_param_dataset:
                  summary: invalid_param (dataset)
                  value:
                    status: 400
                    code: invalid_param
                    message: Dataset does not exist.
                invalid_param_external:
                  summary: invalid_param (external)
                  value:
                    status: 400
                    code: invalid_param
                    message: External datasets are not supported.
                invalid_param_file_too_large:
                  summary: invalid_param (file_too_large)
                  value:
                    status: 400
                    code: invalid_param
                    message: File size exceeded.
                invalid_param_unsupported_file_type:
                  summary: invalid_param (unsupported_file_type)
                  value:
                    status: 400
                    code: invalid_param
                    message: File type not allowed.
                invalid_param_indexing:
                  summary: invalid_param (indexing_technique)
                  value:
                    status: 400
                    code: invalid_param
                    message: indexing_technique is required.
                invalid_param_process_rule:
                  summary: invalid_param (process_rule)
                  value:
                    status: 400
                    code: invalid_param
                    message: process_rule is required.
components:
  schemas:
    Document:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier of the document.
        position:
          type: integer
          description: Display position of the document in the list.
        data_source_type:
          type: string
          description: >-
            How the document was created. `upload_file` for file uploads,
            `notion_import` for Notion imports.
        data_source_info:
          type: object
          description: Raw data source information, varies by `data_source_type`.
        data_source_detail_dict:
          type: object
          description: Detailed data source information including file details.
        dataset_process_rule_id:
          type: string
          description: ID of the processing rule applied to this document.
        name:
          type: string
          description: Document name.
        created_from:
          type: string
          description: >-
            Origin of the document. `api` for API creation, `web` for UI
            creation.
        created_by:
          type: string
          description: ID of the user who created the document.
        created_at:
          type: number
          description: Creation timestamp (Unix epoch in seconds).
        tokens:
          type: integer
          description: Total number of tokens in the document.
        indexing_status:
          type: string
          description: >-
            Current indexing status. `waiting` for queued, `parsing` while
            extracting content, `cleaning` while removing noise, `splitting`
            while chunking, `indexing` while building vectors, `completed` when
            ready, `error` if failed, `paused` if manually paused.
        error:
          type: string
          nullable: true
          description: Error message if indexing failed. `null` when no error.
        enabled:
          type: boolean
          description: Whether the document is enabled for retrieval.
        disabled_at:
          type: number
          nullable: true
          description: Timestamp when the document was disabled. `null` if enabled.
        disabled_by:
          type: string
          nullable: true
          description: ID of the user who disabled the document. `null` if enabled.
        archived:
          type: boolean
          description: Whether the document is archived.
        display_status:
          type: string
          description: >-
            User-facing display status derived from `indexing_status` and
            `enabled` state.
        word_count:
          type: integer
          description: Total word count of the document.
        hit_count:
          type: integer
          description: Number of times the document has been matched in retrieval queries.
        doc_form:
          type: string
          description: >-
            Document chunking mode. `text_model` for standard text chunking,
            `hierarchical_model` for parent-child structure, `qa_model` for QA
            pair extraction.
        doc_metadata:
          type: array
          description: Metadata values assigned to this document.
          items:
            type: object
            properties:
              id:
                type: string
                description: Metadata field identifier.
              name:
                type: string
                description: Metadata field name.
              type:
                type: string
                description: Metadata field value type.
              value:
                type: string
                description: Metadata value for this document.
        summary_index_status:
          type: string
          nullable: true
          description: >-
            Status of the summary index for this document. `null` if summary
            indexing is not configured.
        need_summary:
          type: boolean
          description: Whether a summary needs to be generated for this document.
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API_KEY
      description: >-
        API Key authentication. For all API requests, include your API Key in
        the `Authorization` HTTP Header, prefixed with `Bearer `. Example:
        `Authorization: Bearer {API_KEY}`. **Strongly recommend storing your API
        Key on the server-side, not shared or stored on the client-side, to
        avoid possible API-Key leakage that can lead to serious consequences.**

````