Unlimited-OCR-2 API
Turn a picture or a PDF into Markdown: body text, headings, tables (as HTML) and formulas, plus the type and position of every layout block. $0.001 per page ($1 per 1,000 pages). OpenAI chat completions format, answered synchronously.
Endpoint
The same endpoint and key as the chat models. Put one picture (image_url) or one PDF (file) in messages; no prompt is needed, and any text you add is ignored. Any OpenAI SDK works with base_url set to https://api.apimodels.app/v1.
Code examples
Read the supermarket receipt photo from our review page.
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"}}
]}]
}'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 Markdownimport 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 MarkdownLocal pictures and PDFs
Send local files as base64 data URIs. A PDF goes in a file content part; up to 20 pages per request, chosen with pages.
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": ...}Respuesta
{
"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 is the page as Markdown, with tables as HTML <table>. A multi-page PDF is joined page by page, each starting with <!-- page N -->.
- ocr.pages[] is the structured result: each page's width and height in pixels, the rotation that was corrected, and its layout blocks — type (the layout label, such as title / text / table / image / other), bbox (pixel coordinates [x0, y0, x1, y1]) and content.
- usage_units.pages is the number of pages billed and cost_usd the amount actually charged (after any account discount). The token counts in usage are always 0; this model is not billed by token.
- stream: true is accepted: the result arrives as one complete SSE chunk followed by [DONE].
Parámetros de la solicitud
| Field | Required | Type | Description |
|---|---|---|---|
| model | Yes | string | unlimited-ocr-2 |
| messages | Yes | array | Exactly one picture (image_url) or one PDF (file). Pictures: PNG / JPEG / WebP / BMP / TIFF / GIF. Up to 30MB. |
| pages | No | string | PDFs only: the pages to read, e.g. "1-3,7" (1-based). Without it the whole PDF is read; a PDF over 20 pages must pass it. |
| auto_rotate | No | boolean | Default true: detect orientation and turn sideways or upside-down pages upright before reading. |
| include_image_base64 | No | boolean | Default false: when true, figure regions are cropped from the page and returned as base64 JPEG in ocr.pages[].images. |
Billing
| Price | $0.001 per page ($1 per 1,000 pages) |
| Billed unit | Pages actually read; a picture counts as 1 page |
| Failures | Not charged |
For PDFs the balance is checked again once the page count is known: if it cannot cover every selected page, the whole request returns 402 rather than reading part of it.
Errores
- 400 — No picture, more than one, a link that cannot be downloaded or is not public, an unsupported format, page numbers out of range or more than 20 pages.
- 401 — Invalid API key.
- 402 — Insufficient balance.
- 413 — The file is over 30MB.
- 502 / 503 / 504 — Temporarily unavailable, or not finished within 15 minutes. Not charged; safe to retry.
See also
- Unlimited-OCR-2 model page
- Unlimited-OCR-2 hands-on review — real inputs and outputs: a receipt, a business card, a quote
- Unlimited-SVG API
Preguntas frecuentes
How is the Unlimited-OCR-2 API billed?
$0.001 per page actually read ($1 per 1,000 pages); a picture counts as one page. Failed calls are not charged.
Can it read PDFs?
Yes. Send the PDF as a file content part; up to 20 pages per request, chosen with the pages field (for example "1-3,7"). Pages are returned joined, each starting with <!-- page N -->.
Does it work with the OpenAI SDK?
Yes. It uses POST /v1/chat/completions; set base_url to https://api.apimodels.app/v1 and put the picture in an image_url content part. No prompt is needed.