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

# OCR via AI Gateway

> Extract text and structure from PDFs, images, receipts, and invoices with the AI Gateway OCR endpoint, returning per-page markdown output.

See [HTTP URLs and authentication](/docs/reference/base-urls.md) and the API reference for complete request and response formats.

**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](/docs/reference/ocr/create-ocr.md) API reference.

## Quick start

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

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://router.toqan.ai/eu/v3/router/ocr" \
  -H "Authorization: Bearer $TOQAN_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"
    }
  }'
```

## 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](/docs/reference/ocr/create-ocr.md) reference for the full schema.

## Supported models

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


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