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

# Multi-Page Analysis

> Process and analyze documents across multiple pages with context preservation and cross-document correlation

Process and analyze documents across multiple pages with context preservation and cross-document correlation. Perfect for medical record processing, legal document review, multi-document workflows, and comprehensive document analysis that requires understanding relationships between different document types.

<Frame caption="Multi-Page Document Analysis Example">
  <iframe src="https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.agent/multi-document-input-example.pdf" style={{ width: '100%', height: '600px', border: '1px solid #ddd', borderRadius: '4px' }} title="Patient Referral Form PDF Viewer">
    Your browser does not support PDFs. Please download the PDF to view it: <a href="https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.agent/multi-document-input-example.pdf">Download PDF</a>.
  </iframe>
</Frame>

## Usage Example

<Tip>
  For best results, we recommend using the [Structured Outputs API](/agents/structured-responses) to get responses in a structured and validated data format.
</Tip>

<Info title="Multi-Page Document Analysis">
  The following examples can analyze and triage multiple pages or documents, identify cross-document relationships, extract consistent information across pages, and provide comprehensive analysis with context preservation. The response schema includes page summaries, cross-document connections, and thematic analysis.
</Info>

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  from vlmrun.client import VLMRun

  # Initialize the VLMRun client
  client = VLMRun(api_key="<VLMRUN_API_KEY>")

  # Analyze multi-page medical documents
  response = client.agent.completions.create(
      model="vlmrun-orion-1:auto",
      messages=[
          {
            "role": "user",
            "content": [
              {"type": "text", "text": "Analyze this multi-page medical document set. Extract patient referral page, medical insurance card and identification form in 3 separate fields in JSON format."},
              {"type": "file_url", "file_url": {"url": "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.agent/multi-document-input-example.pdf", "detail": "auto"}}
            ]
          }
      ]
  )

  print(response.choices[0].message.content)
  ```

  ```python Python - Structured Outputs theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  from vlmrun.client import VLMRun
  from pydantic import BaseModel, Field
  from typing import Literal

  # Define the response schema
  class DocumentPage(BaseModel):
    page_id: int = Field(..., description="Page number (0-indexed)")
    document_type: Literal["referral", "insurance-card", "identification"]

  class MultiPageResponse(BaseModel):
    pages: list[DocumentPage] = Field(..., description="List of document pages")

  # Initialize the VLMRun client
  client = VLMRun(api_key="<VLMRUN_API_KEY>")

  # Analyze multi-page document with structured output
  response = client.agent.completions.create(
      model="vlmrun-orion-1:auto",
      messages=[
          {
            "role": "user",
            "content": [
              {"type": "text", "text": "Analyze this multi-page medical document set. Extract patient referral page, medical insurance card and identification form in 3 separate fields in JSON format."},
              {"type": "file_url", "file_url": {"url": "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.agent/multi-document-input-example.pdf", "detail": "auto"}}
            ]
          }
      ],
      response_format={"type": "json_schema", "schema": MultiPageResponse.model_json_schema()},
  )

  # Validate the response
  result = MultiPageResponse.model_validate_json(response.choices[0].message.content)
  # >>> MultiPageResponse(pages=[DocumentPage(page_id=0, document_type="referral"), ...])
  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  import { VlmRun } from "vlmrun";

  const client = new VlmRun({
    apiKey: "<VLMRUN_API_KEY>",
    baseURL: "https://api.vlm.run/v1"
  });

  const response = await client.agent.completions.create({
    model: "vlmrun-orion-1:auto",
    messages: [
      {
        role: "user",
        content: [
          { type: "text", text: "Analyze this multi-page medical document set. Extract patient referral page, medical insurance card and identification form in 3 separate fields in JSON format." },
          { type: "file_url", file_url: { url: "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.agent/multi-document-input-example.pdf", detail: "auto" } }
        ]
      }
    ]
  });

  console.log(response.choices[0].message.content);
  ```

  ```typescript Node.js - Structured Outputs [expandable] theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  import { VlmRun } from "vlmrun";
  import { z } from "zod";
  import { zodToJsonSchema } from "zod-to-json-schema";

  // Define the response schema with Zod
  const MultiPageResponseSchema = z.object({
    pages: z.array(z.object({
      page_id: z.number().int().describe("Page number (0-indexed)"),
      document_type: z.enum(["referral", "insurance-card", "identification"])
    })).describe("List of document pages")
  });

  // Initialize the VLMRun client
  const client = new VlmRun({
    apiKey: "<VLMRUN_API_KEY>",
    baseURL: "https://api.vlm.run/v1"
  });

  // Analyze multi-page document with structured output
  const response = await client.agent.completions.create({
    model: "vlmrun-orion-1:auto",
    messages: [
      {
        role: "user",
        content: [
          { type: "text", text: "Analyze this multi-page medical document set. Extract patient referral page, medical insurance card and identification form in 3 separate fields in JSON format." },
          { type: "file_url", file_url: { url: "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.agent/multi-document-input-example.pdf", detail: "auto" } }
        ]
      }
    ],
    response_format: {
      type: "json_schema",
      schema: zodToJsonSchema(MultiPageResponseSchema)
    }
  });

  const result = MultiPageResponseSchema.parse(JSON.parse(response.choices[0].message.content));
  ```
</CodeGroup>

## FAQ

<AccordionGroup>
  <Accordion title="What types of multi-page analysis are supported?" icon="file-lines">
    * **Cross-Document Correlation**: Identify relationships between different document types
    * **Data Consistency Checking**: Verify data matches across pages and documents
    * **Theme Analysis**: Track recurring themes and topics across pages
    * **Reference Tracking**: Follow references and citations across pages
    * **Content Flow Analysis**: Understand how content flows between pages
  </Accordion>

  <Accordion title="What document types can be analyzed together?" icon="boxes-stacked">
    * **Medical Records**: Referral forms, insurance cards, ID forms, lab reports
    * **Legal Documents**: Contracts, amendments, exhibits, supporting documents
    * **Financial Documents**: Invoices, receipts, statements, tax forms
    * **Academic Papers**: Research papers, appendices, references, figures
    * **Business Reports**: Executive summaries, detailed sections, appendices
  </Accordion>

  <Accordion title="How does cross-document correlation work?" icon="link">
    The system identifies connections between different pages/documents by:

    * **Data Matching**: Finding identical or similar values across documents
    * **Reference Tracking**: Following explicit references between pages
    * **Contextual Analysis**: Understanding semantic relationships
    * **Confidence Scoring**: Providing reliability scores for each connection
  </Accordion>

  <Accordion title="What is the confidence score?" icon="percent">
    The confidence score is a value between 0 and 1 that indicates the reliability of cross-document connections. Higher scores indicate more reliable matches and relationships between pages.
  </Accordion>

  <Accordion title="Can it handle different document formats in one analysis?" icon="file">
    Yes, multi-page analysis can process different document types within a single PDF or across multiple uploaded documents, identifying relationships and correlations between them.
  </Accordion>
</AccordionGroup>
