Perform document extraction inference on the service Experimental; Added in 9.6.0

POST /_inference/document_extraction/{inference_id}

Extract the content of documents, such as PDFs or images of documents, into a textual format.

Required authorization

  • Cluster privileges: monitor_inference

Path parameters

  • inference_id string Required

    The unique identifier for the inference endpoint.

Query parameters

  • timeout string

    The amount of time to wait for the inference request to complete.

    Default value is 120s.

application/json

Body Required

  • input object | array[object] Required

    The documents to extract the content from. Either a content object or an array of content objects.

    content object example:

    "input": {
      "content": {
        "type": "pdf",
        "format": "base64",
        "value": "data:application/pdf;base64,..."
      }
    }
    

    content object array example:

    "input": [
      {
        "content": {
          "type": "pdf",
          "format": "base64",
          "value": "data:application/pdf;base64,..."
        }
      },
      {
        "content": {
          "type": "image",
          "format": "url",
          "value": "https://example.com/scanned-page.png"
        }
      }
    ]
    
    One of:

    A wrapper object which contains a single document to extract the content from.

  • task_settings object

    Task settings for the individual inference request. These settings are specific to the task type you specified and override the task settings specified when initializing the service.

Responses

  • 200 application/json
    Hide response attribute Show response attribute object
    • document_extraction array[object] Required

      The document extraction result object representing the content extracted from a single document.

      Hide document_extraction attributes Show document_extraction attributes object

      The document extraction result object representing the content extracted from a single document.

      • content string Required

        The content extracted from the document.

      • format string Required

        The format of the extracted content, for example markdown.

      • metadata object

        Additional information about the document, such as its title. The available fields depend on the service and model.

        Hide metadata attribute Show metadata attribute object
        • * object Additional properties
POST /_inference/document_extraction/{inference_id}
POST _inference/document_extraction/my-document-extraction-endpoint
{
  "input": [
    {
      "content": {
        "type": "pdf",
        "format": "base64",
        "value": "data:application/pdf;base64,..."
      }
    }
  ]
}
resp = client.inference.document_extraction(
    inference_id="my-document-extraction-endpoint",
    input=[
        {
            "content": {
                "type": "pdf",
                "format": "base64",
                "value": "data:application/pdf;base64,..."
            }
        }
    ],
)
const response = await client.inference.documentExtraction({
  inference_id: "my-document-extraction-endpoint",
  input: [
    {
      content: {
        type: "pdf",
        format: "base64",
        value: "data:application/pdf;base64,...",
      },
    },
  ],
});
response = client.inference.document_extraction(
  inference_id: "my-document-extraction-endpoint",
  body: {
    "input": [
      {
        "content": {
          "type": "pdf",
          "format": "base64",
          "value": "data:application/pdf;base64,..."
        }
      }
    ]
  }
)
$resp = $client->inference()->documentExtraction([
    "inference_id" => "my-document-extraction-endpoint",
    "body" => [
        "input" => array(
            [
                "content" => [
                    "type" => "pdf",
                    "format" => "base64",
                    "value" => "data:application/pdf;base64,...",
                ],
            ],
        ),
    ],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"input":[{"content":{"type":"pdf","format":"base64","value":"data:application/pdf;base64,..."}}]}' "$ELASTICSEARCH_URL/_inference/document_extraction/my-document-extraction-endpoint"
Request examples
Run `POST _inference/document_extraction/my-document-extraction-endpoint` to extract the content of the example PDF document
{
  "input": [
    {
      "content": {
        "type": "pdf",
        "format": "base64",
        "value": "data:application/pdf;base64,..."
      }
    }
  ]
}
Run `POST _inference/document_extraction/my-document-extraction-endpoint` to extract the content of an image of a document referenced by URL as markdown.
{
  "input": {
    "content": {
      "type": "image",
      "format": "url",
      "value": "https://example.com/scanned-page.png"
    }
  },
  "task_settings": {
    "output_format": "markdown"
  }
}
Response examples (200)
An abbreviated response from `POST _inference/document_extraction/my-document-extraction-endpoint`.
{
  "document_extraction": [
    {
      "content": "# Annual Report 2025\n\n...",
      "format": "markdown",
      "metadata": {
        "title": "Annual Report 2025"
      }
    }
  ]
}