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

# Query Document

> Execute a one-off analysis for a document using Morphik On-the-Fly, optionally enforcing structured output and
scheduling a follow-up ingestion.

`ingestion_options` is a JSON string controlling post-analysis ingestion behaviour via keys such as `ingest`,
`metadata`, `use_colpali`, `folder_name`, and `end_user_id`. Additional keys are ignored. A
:class:`DocumentQueryResponse` describing the inline analysis and any queued ingestion is returned.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/morphik/openapi.documented.yml post /ingest/document/query
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers: []
security: []
paths:
  /ingest/document/query:
    post:
      tags:
        - Ingestion
      summary: Query Document
      description: >-
        Execute a one-off analysis for a document using Morphik On-the-Fly,
        optionally enforcing structured output and

        scheduling a follow-up ingestion.


        `ingestion_options` is a JSON string controlling post-analysis ingestion
        behaviour via keys such as `ingest`,

        `metadata`, `use_colpali`, `folder_name`, and `end_user_id`. Additional
        keys are ignored. A

        :class:`DocumentQueryResponse` describing the inline analysis and any
        queued ingestion is returned.
      operationId: query_document_ingest_document_query_post
      parameters:
        - name: authorization
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Authorization
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: >-
                #/components/schemas/Body_query_document_ingest_document_query_post
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocumentQueryResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Morphik from 'morphik';

            const client = new Morphik({
              apiKey: process.env['MORPHIK_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.ingest.documentQuery({
              file: fs.createReadStream('path/to/file'),
              prompt: 'prompt',
            });

            console.log(response.combined_metadata);
        - lang: cURL
          source: |-
            curl https://api.morphik.ai/ingest/document/query \
                -H 'Content-Type: multipart/form-data' \
                -H "Authorization: Bearer $MORPHIK_API_KEY" \
                -F 'file=@/path/to/file' \
                -F prompt=prompt
components:
  schemas:
    Body_query_document_ingest_document_query_post:
      properties:
        file:
          type: string
          format: binary
          title: File
        prompt:
          type: string
          title: Prompt
        response_schema:
          anyOf:
            - type: string
            - type: 'null'
          title: Response Schema
        ingestion_options:
          type: string
          title: Ingestion Options
          default: '{}'
      type: object
      required:
        - file
        - prompt
      title: Body_query_document_ingest_document_query_post
    DocumentQueryResponse:
      properties:
        structured_output:
          anyOf:
            - {}
            - type: 'null'
          title: Structured Output
          description: >-
            Raw structured output returned from Morphik On-the-Fly (may be
            list/dict)
        extracted_metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Extracted Metadata
          description: Structured output coerced to metadata when possible
        text_output:
          anyOf:
            - type: string
            - type: 'null'
          title: Text Output
          description: Raw text returned from Morphik On-the-Fly when no schema is provided
        ingestion_enqueued:
          type: boolean
          title: Ingestion Enqueued
          description: True when the document was queued for ingestion after extraction
          default: false
        ingestion_document:
          anyOf:
            - $ref: '#/components/schemas/Document'
            - type: 'null'
          description: Queued document stub when ingestion_enqueued is true
        input_metadata:
          additionalProperties: true
          type: object
          title: Input Metadata
          description: Original metadata supplied alongside the request
        combined_metadata:
          additionalProperties: true
          type: object
          title: Combined Metadata
          description: Metadata that would be used if ingestion is performed
        ingestion_options:
          $ref: '#/components/schemas/IngestionOptions'
          description: Normalized ingestion options applied to this request
      type: object
      title: DocumentQueryResponse
      description: Response model for document query with optional ingestion follow-up.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    Document:
      properties:
        external_id:
          type: string
          title: External Id
        content_type:
          type: string
          title: Content Type
        filename:
          anyOf:
            - type: string
            - type: 'null'
          title: Filename
        metadata:
          additionalProperties: true
          type: object
          title: Metadata
        metadata_types:
          additionalProperties:
            type: string
          type: object
          title: Metadata Types
        storage_info:
          additionalProperties: true
          type: object
          title: Storage Info
        system_metadata:
          additionalProperties: true
          type: object
          title: System Metadata
        additional_metadata:
          additionalProperties: true
          type: object
          title: Additional Metadata
        chunk_ids:
          items:
            type: string
          type: array
          title: Chunk Ids
        summary_storage_key:
          anyOf:
            - type: string
            - type: 'null'
          title: Summary Storage Key
        summary_version:
          anyOf:
            - type: integer
            - type: 'null'
          title: Summary Version
        summary_bucket:
          anyOf:
            - type: string
            - type: 'null'
          title: Summary Bucket
        summary_updated_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Summary Updated At
        folder_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Folder Name
        end_user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: End User Id
        app_id:
          anyOf:
            - type: string
            - type: 'null'
          title: App Id
        folder_path:
          anyOf:
            - type: string
            - type: 'null'
          title: Folder Path
        folder_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Folder Id
      type: object
      required:
        - content_type
      title: Document
      description: Represents a document stored in the database documents collection
    IngestionOptions:
      properties:
        ingest:
          type: boolean
          title: Ingest
          description: Whether to enqueue ingestion after metadata extraction.
          default: false
        use_colpali:
          type: boolean
          title: Use Colpali
          description: >-
            Whether to use Morphik's ColPali-style embeddings during ingestion
            (recommended for quality).
          default: false
        folder_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Folder Name
          description: >-
            Optional target folder path for the ingested document. Only a single
            folder is supported.
        end_user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: End User Id
          description: Optional end-user scope for the operation.
        metadata:
          additionalProperties: true
          type: object
          title: Metadata
          description: >-
            Metadata to merge into the ingested document when ingestion is
            triggered.
      additionalProperties: false
      type: object
      title: IngestionOptions
      description: Normalized options controlling post-analysis ingestion.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````