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

# PDF Extraction

> Extract structured data from PDF documents using AI

## Authentication

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication
</ParamField>

## Body Parameters

<ParamField body="pdfUrl" type="string" required>
  URL of the PDF document to extract data from
</ParamField>

<ParamField body="schema" type="object" required>
  JSON Schema defining the structure of data to extract
</ParamField>

<ParamField body="prompt" type="string">
  Optional custom prompt to guide extraction
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.hypermodel.ai/api/v1/pdf/extract \
    -H "Content-Type: application/json" \
    -H "x-api-key: your-api-key" \
    -d '{
      "pdfUrl": "https://example.com/financial-report.pdf",
      "schema": {
        "type": "object",
        "properties": {
          "company_name": { "type": "string" },
          "revenue": { "type": "string" },
          "employees": { "type": "number" },
          "founded_year": { "type": "number" }
        }
      },
      "prompt": "Extract company financial information"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.hypermodel.ai/api/v1/pdf/extract', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': 'your-api-key',
    },
    body: JSON.stringify({
      pdfUrl: 'https://example.com/financial-report.pdf',
      schema: {
        type: 'object',
        properties: {
          company_name: { type: 'string' },
          revenue: { type: 'string' },
          employees: { type: 'number' },
          founded_year: { type: 'number' },
        },
      },
      prompt: 'Extract company financial information',
    }),
  });

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.hypermodel.ai/api/v1/pdf/extract',
      headers={
          'Content-Type': 'application/json',
          'x-api-key': 'your-api-key',
      },
      json={
          'pdfUrl': 'https://example.com/financial-report.pdf',
          'schema': {
              'type': 'object',
              'properties': {
                  'company_name': {'type': 'string'},
                  'revenue': {'type': 'string'},
                  'employees': {'type': 'number'},
                  'founded_year': {'type': 'number'},
              },
          },
          'prompt': 'Extract company financial information',
      },
  )

  data = response.json()
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "success": true,
    "data": {
      "company_name": "Example Corp",
      "revenue": "$10M",
      "employees": 50,
      "founded_year": 2020
    }
  }
  ```

  ```json 400 Bad Request theme={null}
  {
    "success": false,
    "error": "Invalid PDF URL: unable to fetch document"
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "error": "Unauthorized",
    "message": "API key is required"
  }
  ```

  ```json 403 Forbidden theme={null}
  {
    "error": "Forbidden",
    "message": "Invalid API key"
  }
  ```
</ResponseExample>

## Use Cases

<AccordionGroup>
  <Accordion title="Financial Report Extraction">
    Extract key financial metrics from annual reports, quarterly statements, or financial summaries.

    ```json theme={null}
    {
      "pdfUrl": "https://example.com/annual-report.pdf",
      "schema": {
        "type": "object",
        "properties": {
          "revenue": { "type": "string" },
          "profit": { "type": "string" },
          "growth_rate": { "type": "string" }
        }
      }
    }
    ```
  </Accordion>

  <Accordion title="Resume Parsing">
    Extract structured information from candidate resumes or CVs.

    ```json theme={null}
    {
      "pdfUrl": "https://example.com/resume.pdf",
      "schema": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "email": { "type": "string" },
          "phone": { "type": "string" },
          "experience": { "type": "array" },
          "education": { "type": "array" }
        }
      }
    }
    ```
  </Accordion>

  <Accordion title="Invoice Data Extraction">
    Parse invoice details for accounting or expense management systems.

    ```json theme={null}
    {
      "pdfUrl": "https://example.com/invoice.pdf",
      "schema": {
        "type": "object",
        "properties": {
          "invoice_number": { "type": "string" },
          "date": { "type": "string" },
          "total": { "type": "number" },
          "items": { "type": "array" }
        }
      }
    }
    ```
  </Accordion>

  <Accordion title="Contract Information">
    Extract key terms and information from legal contracts or agreements.

    ```json theme={null}
    {
      "pdfUrl": "https://example.com/contract.pdf",
      "schema": {
        "type": "object",
        "properties": {
          "parties": { "type": "array" },
          "start_date": { "type": "string" },
          "end_date": { "type": "string" },
          "value": { "type": "string" }
        }
      }
    }
    ```
  </Accordion>
</AccordionGroup>

## Tips for Better Results

<CardGroup cols={2}>
  <Card title="Clear Schema" icon="list">
    Define a clear, specific schema that matches the structure of data in your PDF
  </Card>

  <Card title="Custom Prompts" icon="message">
    Use custom prompts to guide the AI to focus on specific sections or data types
  </Card>

  <Card title="Accessible PDFs" icon="file-pdf">
    Ensure PDFs are text-based or have OCR applied for best extraction results
  </Card>

  <Card title="Test Incrementally" icon="vial">
    Start with simple extractions and gradually add more fields to your schema
  </Card>
</CardGroup>
