---
title: "Unlimited-OCR-2 API:图片和 PDF 转 Markdown,$1 / 千页｜APIMODELS"
description: "apimodels 的 Unlimited-OCR-2 OCR API:把图片或 PDF(每次最多 20 页)发到 OpenAI 兼容的 /v1/chat/completions,拿回带 HTML 表格的 Markdown 和版面块坐标。$0.001 / 页,失败不收费。"
canonical: https://apimodels.app/zh/docs/unlimited-ocr-2
markdown: https://apimodels.app/zh/docs/unlimited-ocr-2.md
language: zh
source: "Generated from the HTML docs page at the canonical URL; the HTML page is the source of truth. Docs index: https://apimodels.app/llms.txt"
---

[Docs](https://apimodels.app/zh/docs) · Unlimited-OCR-2 API

# Unlimited-OCR-2 API

把一张图片或一份 PDF 变成 Markdown:正文、标题、表格(HTML)、公式,外加每个版面块的类型和坐标。$0.001 一页($1 / 千页)。用 OpenAI 的 chat completions 格式,同步返回。

## 端点

和聊天模型同一个端点、同一把 key。messages 里放一张图(image_url)或一份 PDF(file),不需要写提示词,写了也会被忽略。任何 OpenAI SDK 把 base_url 改成 https://api.apimodels.app/v1 就能用。

POST · https://api.apimodels.app/v1/chat/completions

## 代码示例

识别测评页里那张超市小票照片。

```bash
curl https://api.apimodels.app/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "unlimited-ocr-2",
    "messages": [{"role": "user", "content": [
      {"type": "image_url", "image_url": {"url": "https://apimodels.app/unlimited-ocr-2-review/receipt-photo.webp"}}
    ]}]
  }'
```

```python
from openai import OpenAI

client = OpenAI(base_url="https://api.apimodels.app/v1", api_key="YOUR_API_KEY")

resp = client.chat.completions.create(
    model="unlimited-ocr-2",
    messages=[{"role": "user", "content": [
        {"type": "image_url", "image_url": {"url": "https://apimodels.app/unlimited-ocr-2-review/receipt-photo.webp"}},
    ]}],
)
print(resp.choices[0].message.content)  # the page as Markdown
```

```javascript
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.apimodels.app/v1", apiKey: "YOUR_API_KEY" });

const resp = await client.chat.completions.create({
  model: "unlimited-ocr-2",
  messages: [{ role: "user", content: [
    { type: "image_url", image_url: { url: "https://apimodels.app/unlimited-ocr-2-review/receipt-photo.webp" } },
  ] }],
});
console.log(resp.choices[0].message.content); // the page as Markdown
```

## 本地图片与 PDF

本地文件用 base64 data URI。PDF 放在 file 内容块里,一次最多 20 页,用 pages 选页。

```python
import base64
from openai import OpenAI

client = OpenAI(base_url="https://api.apimodels.app/v1", api_key="YOUR_API_KEY")

# A picture: send it as a data URI
b64 = base64.b64encode(open("scan.jpg", "rb").read()).decode()
image = {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64}"}}

# A PDF (up to 20 pages per request; pick pages with "pages")
pdf = base64.b64encode(open("report.pdf", "rb").read()).decode()
file = {"type": "file", "file": {"filename": "report.pdf", "file_data": f"data:application/pdf;base64,{pdf}"}}

resp = client.chat.completions.create(
    model="unlimited-ocr-2",
    messages=[{"role": "user", "content": [file]}],
    extra_body={"pages": "1-3"},
)
print(resp.choices[0].message.content)   # pages joined, each starting with <!-- page N -->
print(resp.model_extra["ocr"]["pages"][0]["blocks"][0])   # {"type": "title", "bbox": [x0, y0, x1, y1], "content": ...}
```

## 响应

```json
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "unlimited-ocr-2",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "邻里优选超市(测试店)\n\n欢迎光临 谢谢惠顾\n\n<table><tr><td colspan=\"2\">小票号:20261203-0417-0086</td></tr>..."
    },
    "finish_reason": "stop"
  }],
  "usage": {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0},
  "ocr": {
    "pages": [{
      "index": 1, "width": 855, "height": 1999, "rotation": 0,
      "blocks": [
        {"type": "other", "bbox": [269, 240, 549, 282], "content": "邻里优选超市(测试店)"},
        {"type": "other", "bbox": [303, 288, 516, 322], "content": "欢迎光临 谢谢惠顾"},
        {"type": "table", "bbox": [146, 350, 685, 1487], "content": "<table><tr><td colspan=\"2\">小票号:20261203-0417-0086</td></tr>..."}
      ],
      "images": [],
      "warnings": []
    }]
  },
  "usage_units": {"pages": 1, "cost_usd": 0.001}
}
```

- choices\[0\].message.content 是整页 Markdown,表格是 HTML <table>。多页 PDF 按页拼接,每页以 <!-- page N --> 开头。
- ocr.pages\[\] 是结构化结果:每页的宽高(像素)、自动纠正的旋转角度、以及版面块 blocks —— type(版面标签,如 title / text / table / image / other)、bbox(像素坐标 \[x0, y0, x1, y1\])、content。
- usage_units.pages 是这次计费的页数,cost_usd 是实际扣款(已含你账户的折扣)。usage 里的 token 数恒为 0,本模型不按 token 计费。
- stream: true 也接受:结果会作为一个完整的 SSE 块返回,然后是 \[DONE\]。

## 请求参数

| 字段                   | 必填 | 类型      | 说明                                                                               |
| -------------------- | -- | ------- | -------------------------------------------------------------------------------- |
| model                | 是  | string  | unlimited-ocr-2                                                                  |
| messages             | 是  | array   | 恰好一张图(image_url)或一份 PDF(file)。图片:PNG / JPEG / WebP / BMP / TIFF / GIF。文件最大 30MB。 |
| pages                | 否  | string  | 仅 PDF:要识别的页,如 "1-3,7"(从 1 开始)。不传就识别全部,超过 20 页的 PDF 必须传。                          |
| auto_rotate          | 否  | boolean | 默认 true:先判断方向,把横放、倒置的页摆正再识别。                                                     |
| include_image_base64 | 否  | boolean | 默认 false:为 true 时,页面里的插图区域裁成 JPEG,以 base64 放进 ocr.pages\[\].images。              |

## 计费

| 价格   | $0.001 每页($1 / 千页) |
| ---- | ------------------ |
| 计费单位 | 实际识别的页数;一张图算 1 页   |
| 失败   | 不收费                |

PDF 的余额检查在拿到页数之后再做一次:余额不够识别全部所选页时,整单返回 402,不会只识别一部分。

## 错误

- 400 — 没有图、放了两张图、链接下载不了或不是公网地址、文件格式不支持、页码超范围或超过 20 页。
- 401 — API key 无效。
- 402 — 余额不足。
- 413 — 文件超过 30MB。
- 502 / 503 / 504 — 服务暂时不可用或 15 分钟内没完成。不收费,可以直接重试。

## 更多

- [Unlimited-OCR-2 模型页](https://apimodels.app/zh/models/unlimited-ocr-2)
- [Unlimited-OCR-2 实测](https://apimodels.app/zh/access/unlimited-ocr-2-review) — 小票、名片、报价单的真实输入与输出
- [Unlimited-SVG API](https://apimodels.app/zh/docs/unlimited-svg)

## 常见问题

**Unlimited-OCR-2 API 怎么计费?**

按实际识别的页数,每页 $0.001($1 / 千页);一张图算 1 页。失败不收费。

**能识别 PDF 吗?**

能。PDF 放在 file 内容块里,每次最多 20 页,用 pages 字段选页(如 "1-3,7")。各页按顺序拼接返回,每页以 <!-- page N --> 开头。

**能用 OpenAI SDK 调吗?**

能。走 POST /v1/chat/completions,base_url 设为 https://api.apimodels.app/v1,图片放在 image_url 内容块里,不需要写提示词。
