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

# Router SDK Reference

> Run OCR through the AI Gateway with the Node.js and Python SDKs to extract text from documents while preserving structure and hierarchy.

## Router

### Ocr

Extracts text content while maintaining document structure and hierarchy

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.router.ocr(model="mistral/mistral-ocr-4-0", document={
          "type": "document_url",
          "document_url": "https://example.com/invoice.pdf",
      })

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.router.ocr({
      model: "mistral/mistral-ocr-4-0",
      document: {
        type: "document_url",
        documentUrl: "https://example.com/invoice.pdf",
      },
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "model": str,  # required
        "document": Union[Document1, Document2],  # required
        "pages": List[int],  # optional
        "ocr_settings": {  # optional
            "include_image_base64": Optional[bool],
            "max_images_to_include": Optional[int],
            "image_min_size": Optional[int],
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      model: string;  // required
      document: Document1 | Document2;  // required
      pages?: number[];
      ocrSettings?: {
        includeImageBase64?: boolean;
        maxImagesToInclude?: number;
        imageMinSize?: number;
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "model": str,
        "pages": [{
            "index": float,
            "markdown": str,
            "images": [{
                "id": str,
                "image_base64": Optional[str],
            }],
            "dimensions": {  # optional
                "dpi": int,
                "height": int,
                "width": int,
            },
        }],
        "usage": Union[Usage1, Usage2],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      model: string;
      pages: {
        index: number;
        markdown: string;
        images: {
          id: string;
          imageBase64?: string;
        }[];
        dimensions?: {
          dpi: number;
          height: number;
          width: number;
        };
      }[];
      usage: Usage1 | Usage2;
    }
    ```
  </CodeGroup>
</Expandable>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.