> ## 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 reasoning (async)

> Initiates an asynchronous document reasoning process based on a task. Returns an ID for tracking.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/samplehc/openapi.documented.yml post /api/v2/documents/legacy/reason
openapi: 3.0.3
info:
  title: Sample Healthcare API
  description: API for Sample Healthcare
  version: 1.0.0
servers: []
security: []
paths:
  /api/v2/documents/legacy/reason:
    post:
      tags:
        - Document
      summary: Document reasoning (async)
      description: >-
        Initiates an asynchronous document reasoning process based on a task.
        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 apply reasoning to.
                task:
                  anyOf:
                    - type: object
                      properties:
                        id:
                          type: string
                        label:
                          type: string
                        type:
                          type: string
                          enum:
                            - reasoning
                        description:
                          type: string
                      required:
                        - id
                        - label
                        - type
                        - description
                      additionalProperties: false
                    - type: object
                      properties:
                        id:
                          type: string
                        label:
                          type: string
                        type:
                          type: string
                          enum:
                            - extraction
                        description:
                          type: string
                        response_schema:
                          anyOf:
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - text
                              required:
                                - type
                              additionalProperties: false
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - boolean
                              required:
                                - type
                              additionalProperties: false
                      required:
                        - id
                        - label
                        - type
                        - description
                        - response_schema
                      additionalProperties: false
                    - type: object
                      properties:
                        id:
                          type: string
                        label:
                          type: string
                        type:
                          type: string
                          enum:
                            - array-extraction
                        description:
                          type: string
                        response_schema:
                          type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - text
                          required:
                            - type
                          additionalProperties: false
                      required:
                        - id
                        - label
                        - type
                        - description
                        - response_schema
                      additionalProperties: false
                  description: The task schema defining the reasoning process.
              required:
                - documents
                - task
              additionalProperties: false
        required: true
      responses:
        '202':
          description: Accepted. Legacy reasoning process initiated.
          content:
            application/json:
              schema:
                type: object
                properties:
                  asyncResultId:
                    type: string
                    description: The ID to track the asynchronous reasoning 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 legacy reasoning.
                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.legacy.reason(
                documents=[{
                    "id": "id",
                    "file_name": "fileName",
                }],
                task={
                    "id": "id",
                    "description": "description",
                    "label": "label",
                    "type": "reasoning",
                },
            )
            print(response.async_result_id)

````