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

# Analyze Document

> Analyze a document by asking questions. Unlike `/extract`, this endpoint
can **compute, reason, and derive** values that aren't explicitly written
in the document.

Upload a file (or provide a URL) along with a typed schema. Each field
must have a `type` and `description`.

**Example schema**:
```json
{
  "total_cost": {"type": "number", "description": "Sum all line item amounts"},
  "is_auto_renew": {"type": "boolean", "description": "Does this contract auto-renew?"},
  "risk_level": {"type": "string", "enum": ["low", "medium", "high"], "description": "Legal risk level"}
}
```

**Supported types**: `string`, `number`, `integer`, `boolean`, `array`, `object`

Every answer includes:
- The computed answer (type-enforced)
- Reasoning explaining how it was derived
- Source text snippets from the document
- Confidence level

**Pricing**: 2 credits/page (min 5) for documents, 10 credits for websites.



## OpenAPI

````yaml /openapi.json post /api/v1/analyze
openapi: 3.1.0
info:
  title: The Drive AI API
  description: >

    ## The Drive AI API


    One API for screenshots, markdown extraction, structured data extraction,

    and more. 107+ file formats supported.


    ## Endpoints


    | Endpoint | Credits | Description |

    |----------|---------|-------------|

    | `GET /{url}` | 1 | Screenshot any URL |

    | `GET /md/{url}` | 1 | Convert any URL to markdown |

    | `POST /api/v1/thumbnails/generate` | 1 | Generate thumbnail from file or
    URL |

    | `POST /api/v1/markdown/convert` | 1 | Convert file/URL to markdown |

    | `POST /api/v1/extract` | 1/page or 5/site | Extract structured data |

    | `POST /api/v1/analyze` | 2/page or 10/site | Analyze — compute, reason,
    derive |


    ## Authentication


    All protected endpoints require an `X-API-Key` header:

    ```bash

    curl https://dev.thedrive.ai/stripe.com \
      -H "X-API-Key: tda_live_your_key_here"
    ```


    Get your API key at https://dev.thedrive.ai/login


    ## Pricing


    - **Free**: 100 credits/month, no card required

    - **Pro**: $0.01/credit, pay-as-you-go

    - **Enterprise**: Volume pricing, contact us
  version: 1.3.0
servers: []
security: []
tags:
  - name: screenshots
    description: Screenshot and thumbnail generation
  - name: markdown
    description: URL and document to markdown conversion
  - name: extraction
    description: Structured data extraction from documents
  - name: thumbnails
    description: Thumbnail generation via file upload or URL
  - name: health
    description: Service health and readiness probes
paths:
  /api/v1/analyze:
    post:
      tags:
        - analysis
      summary: Analyze Document
      description: >-
        Analyze a document by asking questions. Unlike `/extract`, this endpoint

        can **compute, reason, and derive** values that aren't explicitly
        written

        in the document.


        Upload a file (or provide a URL) along with a typed schema. Each field

        must have a `type` and `description`.


        **Example schema**:

        ```json

        {
          "total_cost": {"type": "number", "description": "Sum all line item amounts"},
          "is_auto_renew": {"type": "boolean", "description": "Does this contract auto-renew?"},
          "risk_level": {"type": "string", "enum": ["low", "medium", "high"], "description": "Legal risk level"}
        }

        ```


        **Supported types**: `string`, `number`, `integer`, `boolean`, `array`,
        `object`


        Every answer includes:

        - The computed answer (type-enforced)

        - Reasoning explaining how it was derived

        - Source text snippets from the document

        - Confidence level


        **Pricing**: 2 credits/page (min 5) for documents, 10 credits for
        websites.
      operationId: analyze_document_api_v1_analyze_post
      parameters:
        - name: X-API-Key
          in: header
          required: false
          schema:
            type: string
            title: X-Api-Key
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Body_analyze_document_api_v1_analyze_post'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnalyzeResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '413':
          description: File too large
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '503':
          description: AI service unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    Body_analyze_document_api_v1_analyze_post:
      properties:
        file:
          anyOf:
            - type: string
              contentMediaType: application/octet-stream
            - type: 'null'
          title: File
          description: File to analyze
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
          description: URL to fetch file from
        url_headers:
          anyOf:
            - type: string
            - type: 'null'
          title: Url Headers
          description: JSON-encoded headers for URL auth
        schema:
          type: string
          title: Schema
          description: >-
            JSON schema — keys are field names, values describe what to compute
            or answer
        include_steps:
          type: boolean
          title: Include Steps
          description: Include the agent's reasoning trace (tool calls) in each answer
          default: false
        sync:
          type: boolean
          title: Sync
          description: Set to false to process asynchronously. Returns a task_id to poll.
          default: true
        webhook_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Webhook Url
          description: URL to POST the result to when async processing completes.
      type: object
      required:
        - schema
      title: Body_analyze_document_api_v1_analyze_post
    AnalyzeResponse:
      properties:
        success:
          type: boolean
          title: Success
          default: true
        data:
          additionalProperties: true
          type: object
          title: Data
          description: Computed/derived values keyed by field name
        confidence:
          additionalProperties:
            type: number
          type: object
          title: Confidence
          description: Per-field confidence scores (0.0–1.0)
        sources:
          additionalProperties:
            items:
              type: string
            type: array
          type: object
          title: Sources
          description: Per-field source text snippets from the document
        reasoning:
          additionalProperties:
            type: string
          type: object
          title: Reasoning
          description: Per-field step-by-step explanation of how the answer was derived
        steps:
          additionalProperties:
            items:
              $ref: '#/components/schemas/AgentStepResponse'
            type: array
          type: object
          title: Steps
          description: >-
            Per-field agent reasoning trace (tool calls). Empty unless
            include_steps=true.
        filename:
          type: string
          title: Filename
          description: Original filename or URL
        content_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Content Type
          description: Detected MIME type
        model_used:
          type: string
          title: Model Used
          description: Model used for analysis
        text_length:
          type: integer
          title: Text Length
          description: Length of extracted text
        total_pages:
          type: integer
          title: Total Pages
          description: Total pages in the document (0 for non-paginated files)
          default: 0
        credits_used:
          type: integer
          title: Credits Used
          description: Credits consumed
          default: 0
        schema_format:
          anyOf:
            - $ref: '#/components/schemas/SchemaFormat'
            - type: 'null'
          description: 'Schema format: always ''typed'''
      type: object
      required:
        - data
        - filename
        - model_used
        - text_length
      title: AnalyzeResponse
      description: Response for document analysis — flat parallel dicts matching /extract.
      example:
        confidence:
          is_overdue: 0.72
          total_cost: 0.95
        content_type: application/pdf
        credits_used: 10
        data:
          is_overdue: true
          total_cost: 1500
        filename: invoice.pdf
        model_used: gpt-5.1
        reasoning:
          is_overdue: Due date 2025-01-15 has passed.
          total_cost: 'Summed 3 line items: $500 + $600 + $400'
        sources:
          is_overdue:
            - 'Due Date: January 15, 2025'
          total_cost:
            - 'Item A: $500'
            - 'Item B: $600'
            - 'Item C: $400'
        success: true
        text_length: 3200
        total_pages: 5
    ErrorResponse:
      properties:
        success:
          type: boolean
          title: Success
          default: false
        error:
          type: string
          title: Error
          description: Error type
        detail:
          type: string
          title: Detail
          description: Human-readable error message
      type: object
      required:
        - error
        - detail
      title: ErrorResponse
      description: Standard error response.
      example:
        detail: File size exceeds maximum allowed (50MB)
        error: validation_error
        success: false
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    AgentStepResponse:
      properties:
        tool:
          type: string
          title: Tool
          description: Tool that was called
        args:
          additionalProperties: true
          type: object
          title: Args
          description: Arguments passed to the tool
        result_preview:
          type: string
          title: Result Preview
          description: First 200 chars of the tool output
          default: ''
      type: object
      required:
        - tool
      title: AgentStepResponse
      description: One step in the agent's reasoning trace.
    SchemaFormat:
      type: string
      enum:
        - typed
      title: SchemaFormat
      description: Schema format used for extraction/analysis.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````