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

# Document extraction (async)

> Initiates a modern, flexible asynchronous data extraction process using a JSON schema for the desired output and a prompt. Returns an ID for tracking.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/samplehc/openapi.documented.yml post /api/v2/documents/extract
openapi: 3.0.3
info:
  title: Sample Healthcare API
  description: API for Sample Healthcare
  version: 1.0.0
servers: []
security: []
paths:
  /api/v2/documents/extract:
    post:
      tags:
        - Document
      summary: Document extraction (async)
      description: >-
        Initiates a modern, flexible asynchronous data extraction process using
        a JSON schema for the desired output and a prompt. Returns an ID for
        tracking.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                documents:
                  type: array
                  items:
                    type: object
                    properties:
                      id:
                        type: string
                      fileName:
                        type: string
                    required:
                      - id
                      - fileName
                    additionalProperties: false
                  description: An array of documents to extract data from.
                responseJsonSchema:
                  type: object
                  additionalProperties: {}
                  description: >-
                    A JSON schema defining the structure of the desired
                    extraction output.
                prompt:
                  type: string
                  description: A prompt guiding the extraction process.
                reasoningEffort:
                  type: string
                  enum:
                    - minimal
                    - low
                    - medium
                    - high
                    - xhigh
                  description: >-
                    Optional control over the reasoning effort for extraction.
                    `minimal` and `xhigh` are only supported by newer OpenAI
                    models (e.g. GPT-5 family supports `minimal`; GPT-5.5
                    supports `xhigh`).
                model:
                  type: string
                  enum:
                    - reasoning-3-mini
                    - reasoning-3
                    - base-5
                    - base-5-mini
                    - base-5-nano
                    - base-4.1
                    - base-4.1-mini
                    - base-4.1-nano
                    - base-5.2
                    - base-5.2-chat-latest
                    - base-5.4
                    - base-5.4-mini
                    - base-5.5
                    - qwen3-next-80b-thinking
                    - qwen3-next-80b-instruct
                    - glm-4.7
                    - deepseek-v3.2
                    - kimi-k2-thinking
                    - gemini-3-pro
                    - gemini-3-flash
                    - gemini-2.5-pro
                    - gemini-2.5-flash
                    - gemini-2.5-flash-lite
                  default: reasoning-3-mini
                  description: The model to use for extraction.
                rerankerModelId:
                  type: string
                  enum:
                    - cohere.rerank-v3-5:0
                    - amazon.rerank-v1:0
                  description: Optional reranker model ID override for relevance filtering.
                forceReranker:
                  type: boolean
                  default: false
                  description: >-
                    Force using the reranker for relevance filtering even with
                    smaller document sets.
                useNativeStructuredOutput:
                  type: boolean
                  description: >-
                    Deprecated. Accepted for backwards compatibility and
                    ignored.
                useTypeScriptExtraction:
                  type: boolean
                  description: >-
                    Deprecated. Accepted for backwards compatibility and
                    ignored.
                priority:
                  type: string
                  enum:
                    - interactive
                    - non-interactive
                    - background
                  default: interactive
                  description: >-
                    The priority of the extraction task. Non-interactive is
                    lower priority. Background are tasks that can be run in the
                    background while the user is doing other things.
                ocrEnhance:
                  type: object
                  properties:
                    summarizeFigures:
                      type: boolean
                      description: Whether to summarize figures during OCR.
                    agentic:
                      type: array
                      items:
                        anyOf:
                          - type: object
                            properties:
                              scope:
                                type: string
                                enum:
                                  - figure
                              prompt:
                                type: string
                                description: Prompt for figure analysis.
                            required:
                              - scope
                              - prompt
                            additionalProperties: false
                          - type: object
                            properties:
                              scope:
                                type: string
                                enum:
                                  - text
                              prompt:
                                type: string
                                description: Optional prompt for text analysis.
                            required:
                              - scope
                            additionalProperties: false
                          - type: object
                            properties:
                              scope:
                                type: string
                                enum:
                                  - table
                              prompt:
                                type: string
                                description: >-
                                  Optional prompt to guide table reconstruction
                                  (merged cells, multi-level headers, faint
                                  borders).
                            required:
                              - scope
                            additionalProperties: false
                      description: Agentic enhancement configuration.
                  required:
                    - summarizeFigures
                    - agentic
                  additionalProperties: false
                  description: >-
                    OCR enhancement configuration for figure, text, and table
                    analysis.
                ocrQuality:
                  type: string
                  enum:
                    - high
                    - low
                  description: OCR quality setting
                filterFailedPdfs:
                  type: boolean
                  default: false
                  description: Filter out failed pdfs
              required:
                - documents
                - responseJsonSchema
                - prompt
              additionalProperties: false
        required: true
      responses:
        '202':
          description: Accepted. Advanced extraction process initiated.
          content:
            application/json:
              schema:
                type: object
                properties:
                  asyncResultId:
                    type: string
                    description: The ID to track the asynchronous extraction task.
                required:
                  - asyncResultId
                additionalProperties: false
        '400':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: The error message.
                  message:
                    type: string
                    description: The message.
                  statusCode:
                    type: number
                    description: The status code.
                  details:
                    type: object
                    additionalProperties: {}
                    description: The details of the error
                additionalProperties: true
        '404':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Not Found, one or more specified documents do not exist.
                required:
                  - error
                additionalProperties: false
        '500':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: >-
                      Internal server error while initiating advanced
                      extraction.
                required:
                  - error
                additionalProperties: false
      x-codeSamples:
        - lang: Python
          source: |-
            import os
            from samplehc import SampleHealthcare

            client = SampleHealthcare(
                api_key=os.environ.get("SAMPLEHC_API_KEY"),  # This is the default and can be omitted
            )
            response = client.v2.documents.extract(
                documents=[{
                    "id": "id",
                    "file_name": "fileName",
                }],
                prompt="prompt",
                response_json_schema={
                    "foo": "bar"
                },
            )
            print(response.async_result_id)

````