> ## 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.

# OCR via AI Gateway

> Extract text and structure from documents and images through the AI Gateway with a dedicated OCR endpoint.

**Use Cases**

* Extracting text and layout from scanned PDFs and images.
* Digitizing receipts, invoices, and forms into structured markdown.
* Preprocessing documents for downstream RAG or analytics pipelines.
* Turning uploaded files into searchable, machine-readable content.

***

## Overview

Use **`POST /v3/router/ocr`** on the **AI Gateway** to run OCR on a document or image. The endpoint returns per-page markdown that preserves document structure and hierarchy, along with any extracted images.

<Note>
  For the full request and response schema, see the [Create OCR](/reference/ocr/create-ocr) API reference.
</Note>

## Quick start

Send a document URL or image URL and specify the OCR model to use.

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.orq.ai/v3/router/ocr" \
    -H "Authorization: Bearer $ORQ_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "mistral/mistral-ocr-4-0",
      "document": {
        "type": "document_url",
        "document_url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "document_name": "dummy.pdf"
      }
    }'
  ```

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

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

  const result = await orq.router.ocr({
    model: "mistral/mistral-ocr-4-0",
    document: {
      type: "document_url",
      documentUrl: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
      documentName: "dummy.pdf",
    },
  });

  console.log(result);
  ```

  ```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://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
              "document_name": "dummy.pdf",
          },
      )

      print(res)
  ```
</CodeGroup>

## Input types

The `document` field accepts either a document URL or an image URL.

| Type           | Field          | Description                                                                          |
| -------------- | -------------- | ------------------------------------------------------------------------------------ |
| `document_url` | `document_url` | URL of the document (e.g. PDF) to process. Optional `document_name`.                 |
| `image_url`    | `image_url`    | Base64-encoded image data, or an object with a `url` and an optional `detail` field. |

## Options

Additional fields control which pages are processed and how images are returned.

| Field                                | Description                                                                  |
| ------------------------------------ | ---------------------------------------------------------------------------- |
| `pages`                              | Array of 0-based page indices to process. Omit or pass `null` for all pages. |
| `ocr_settings.include_image_base64`  | Return extracted images inline as base64 in the response.                    |
| `ocr_settings.max_images_to_include` | Maximum number of images to include per page.                                |
| `ocr_settings.image_min_size`        | Minimum height and width (pixels) for an image to be included.               |

## Response

Each response includes the model used, an array of pages with extracted `markdown` and `images`, and a `usage` object counting pages or tokens processed. See the [Create OCR](/reference/ocr/create-ocr) reference for the full schema.

## Supported models

For the current list of OCR models, see [OCR models](/docs/ai-gateway/supported-models#ocr-models) on the Supported Models page.
