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

# baidu/unlimited-ocr

> Long-horizon document parsing with batched multi-page OCR.

Long-horizon document parsing with batched multi-page OCR. Accepts one
`image_url` or a `document_url` PDF; no text-only input. The context window is
32,768 tokens, with a maximum output of 24,576 tokens. Aliases include
`baidu/Unlimited-OCR` and `unlimited-ocr`. The model weights are
[`baidu/Unlimited-OCR`](https://huggingface.co/baidu/Unlimited-OCR).

## Output by method

| Method               | Payload kind | Image `content.object` | Payload                                                                   |
| -------------------- | ------------ | ---------------------- | ------------------------------------------------------------------------- |
| `markdown` (default) | markdown     | none                   | Layout-tagged text with pixel bounding boxes, one `<page>` block per page |
| `multi_page`         | markdown     | none                   | Continuous plain text from an 8-page sliding window, no `<page>` blocks   |

Both methods return the Markdown-kind payload. `multi_page` reads an 8-page
sliding window per model call by default. Set `method_params.window_size` to
change the window size. The maximum is one `image_url` or one `document_url`.

Text mode emits a bare payload string for one image, and one `<document>` block
per PDF. With `markdown`, each document contains one `<page>` block per page
with layout-tagged lines in the form `block_type [x1, y1, x2, y2]text`. With
`multi_page`, the `<document>` block carries continuous plain text with no
`<page>` blocks or layout tags. In JSON mode, the response has a `data` array
with `kind` set to `image` or `document`; it does not include top-level `model`
or `method` keys. See [Methods & Response Format](/gateway/methods).

## Request

<CodeGroup>
  ```bash CLI theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  vlmrun gw chat https://storage.googleapis.com/vlm-data-public-prod/hub/examples/finance.sec-filings/tsla-8k.pdf \
    -m baidu/unlimited-ocr --method markdown
  ```

  ```python Python [expandable] theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://gateway.vlm.run/v1/openai",
      api_key="<VLMRUN_API_KEY>",
  )

  response = client.chat.completions.create(
      model="baidu/unlimited-ocr",
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "document_url",
                      "document_url": {
                          "url": "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/finance.sec-filings/tsla-8k.pdf"
                      },
                  },
              ],
          }
      ],
      extra_body={"method": "markdown"},
  )

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

  ```bash cURL [expandable] theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  curl https://gateway.vlm.run/v1/openai/chat/completions \
    -X POST \
    -H "Authorization: Bearer $VLMRUN_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "baidu/unlimited-ocr",
      "method": "markdown",
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "document_url",
              "document_url": {
                "url": "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/finance.sec-filings/tsla-8k.pdf"
              }
            }
          ]
        }
      ]
    }'
  ```
</CodeGroup>

To read a document in sliding windows, use `multi_page` and set
`window_size` with the Python SDK:

```python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
response = client.chat.completions.create(
    model="baidu/unlimited-ocr",
    messages=[...],
    extra_body={
        "method": "multi_page",
        "method_params": {"window_size": 8},
    },
)
```

The equivalent CLI request is:

```bash theme={"theme":{"light":"github-light","dark":"dark-plus"}}
vlmrun gw chat tsla-8k.pdf -m unlimited-ocr \
  --method multi_page --method-params '{"window_size": 8}'
```

## Response

<Tabs>
  <Tab title="Text mode">
    With `markdown`, a PDF returns one `<document>` block with one `<page>`
    block per page:

    ```text theme={"theme":{"light":"github-light","dark":"dark-plus"}}
    <document filename="tsla-8k.pdf" source_url="…" media_type="application/pdf" pages="5" dpi="96" bytes="38884">
    <page index="0" dpi="96" width="816" height="1056">
    title [230, 89, 768, 129]UNITED STATES SECURITIES AND EXCHANGE COMMISSION
    text [389, 130, 604, 145]WASHINGTON, DC 20549
    …
    table [21, 803, 978, 842]<table>Title of each classTrading Symbol(s)…</table>
    </page>
    …
    </document>
    ```

    A single image returns the payload string alone, with no wrapper. With
    `multi_page`, the `<document>` block carries continuous plain text with no
    `<page>` blocks or layout tags.
  </Tab>

  <Tab title="JSON mode">
    A PDF returns a `data` array with a document entry and page content:

    ```json theme={"theme":{"light":"github-light","dark":"dark-plus"}}
    {
      "data": [
        {
          "kind": "document",
          "source": "tsla-8k.pdf",
          "num_pages": 5,
          "pages": [
            {
              "index": 0,
              "width": 816,
              "height": 1056,
              "content": "title [314, 88, 765, 129]UNITED STATES\nSECURITIES AND EXCHANGE COMMISSION\ntext [389, 130, 603, 144]WASHINGTON, DC 20549\n…"
            }
          ]
        }
      ]
    }
    ```

    With `multi_page`, the document entry carries one `content` string and no
    `pages` array. An image returns a `data` array with an image entry:

    ```json theme={"theme":{"light":"github-light","dark":"dark-plus"}}
    {
      "data": [
        {
          "kind": "image",
          "image_hash": "sha256:…",
          "image_width": 640,
          "image_height": 480,
          "content": "…"
        }
      ]
    }
    ```
  </Tab>
</Tabs>
