---
title: "Query Document"
method: POST
path: "/ingest/document/query"
tags: ["Ingestion"]
---

# Query Document

`POST /ingest/document/query`

Run an on-demand Gemini document query with optional structured output and ingestion.

Args:
    file: Uploaded source document (PDF or another supported MIME type).
    prompt: Natural-language instruction to execute against the document.
    schema: Optional JSON schema enforcing structured Gemini output.
    ingestion_options: JSON object controlling ingestion follow-up (keys: ingest, use_colpali, folder_name, end_user_id, metadata).

Returns:
    DocumentQueryResponse containing Gemini outputs, original metadata, and ingestion status details.

## Headers

- `authorization` string

## Response `200`

Successful Response

- DocumentQueryResponse — Response model for document query with optional ingestion follow-up.
  - `structured_output` unknown
  - `extracted_metadata` object, nullable — Structured output coerced to metadata when possible
  - `text_output` string, nullable — Raw text returned from Gemini when no schema is provided
  - `ingestion_enqueued` boolean — True when the document was queued for ingestion after extraction
  - `ingestion_document` Document — Represents a document stored in the database documents collection
    - `external_id` string
    - `content_type` string, required
    - `filename` string, nullable
    - `metadata` object
    - `storage_info` object
    - `storage_files` StorageFileInfo[]
      - `bucket` string, required
      - `key` string, required
      - `version` integer
      - `filename` string, nullable
      - `content_type` string, nullable
      - `timestamp` string, date-time
    - `system_metadata` object
    - `additional_metadata` object
    - `chunk_ids` string[]
    - `folder_name` string, nullable
    - `end_user_id` string, nullable
    - `app_id` string, nullable
  - `input_metadata` object — Original metadata supplied alongside the request
  - `combined_metadata` object — Metadata that would be used if ingestion is performed
  - `ingestion_options` object — Normalized ingestion options applied to this request

## Other responses

- `422` — Validation Error

## Changes

- **2025-11-05** `9ade02dd7b1d` — 1 info
  - endpoint added

[Change history](https://skmtc.dev/morphik-org/apis/fastapi/changes/ingest/document/query/post.md)

---

[API](https://skmtc.dev/morphik-org/apis/fastapi.md) · [All operations](https://skmtc.dev/morphik-org/apis/fastapi/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/morphik-org/fastapi/revisions/9ade02dd7b1d/schema)
