Language
Inference Space Docs

OCR Text Recognition

POST /v1/recognize for image/PDF text recognition with multipart upload and multiple OCR providers.

Inference Space provides OCR text recognition: upload an image or PDF and receive structured recognized text and layout blocks (blocks). The endpoint accepts multipart/form-data uploads and can route requests to multiple OCR providers.

The private deployment API is identical; only replace the Base domain → Enterprise private deployment.

Overview

  • Endpoint: POST https://ai.inf.space/v1/recognize, multipart/form-data.
  • OCR providers: paddleocr, volcengine, and aliyun. The enabled and default providers are shown in the console.

Authentication and Base

  • Host: OCR is a master/control-plane endpoint at https://ai.inf.space; send curl and SDK requests to the documented /v1/recognize path.
  • Authentication header: Authorization: Bearer $TOS_API_KEY. Keys start with gk_.
  • scope: ai:ocr is required. Select it when creating the key; the ai:* wildcard also works.

See Authentication.

Fields

FieldTypeRequiredDescription
imagefileYesImage or PDF file to recognize
scenestringNoRecognition scene, default general; options: general / document / receipt / idcard
languagestringNoRecognition language, default zh-CN
formatstringNoFile format; inferred from the filename extension or MIME type when omitted
  • Supported formats: png / jpg (jpeg is normalized to jpg) / webp / bmp / pdf.
  • Maximum image size: 50 MB. Larger files return 400.

Request examples

  curl "https://ai.inf.space/v1/recognize" \
  -H "Authorization: Bearer $TOS_API_KEY" \
  -F "image=@invoice.png" \
  -F "scene=document" \
  -F "language=zh-CN"
import os
import requests

with open("invoice.png", "rb") as f:
    resp = requests.post(
        "https://ai.inf.space/v1/recognize",
        headers={"Authorization": f"Bearer {os.environ['TOS_API_KEY']}"},
        data={"scene": "document", "language": "zh-CN"},
        files={"image": ("invoice.png", f, "image/png")},
        timeout=120,
    )
resp.raise_for_status()
data = resp.json()
print(data["text"])
import fs from "node:fs";

const form = new FormData();
form.set("scene", "document");
form.set("language", "zh-CN");
form.append("image", new Blob([fs.readFileSync("invoice.png")]), "invoice.png");

const resp = await fetch("https://ai.inf.space/v1/recognize", {
  method: "POST",
  headers: { "Authorization": `Bearer ${process.env.TOS_API_KEY}` },
  body: form,
});
const data = await resp.json();
console.log(data.text);

Response

The response is JSON: text contains the concatenated full-page text, and blocks contains layout blocks with coordinates. Multi-page documents such as PDFs include page_count and per-page results in pages.

{
  "text": "Invoice code: 031001900111\nTotal: CNY 1,280.00",
  "blocks": [
    { "text": "Invoice code: 031001900111", "box": [10, 12, 220, 40], "score": 0.99 }
  ],
  "page_count": 1,
  "pages": [
    { "text": "...", "blocks": [] }
  ]
}

The coordinate precision of blocks and the score field may vary slightly between OCR providers. If layout coordinates are critical, use the same provider consistently and verify it in the console.

Error handling

  • 400: Invalid parameters, an empty file, an unsupported format, a file larger than 50 MB, or an unreadable image (invalid_image).
  • 429: Rate limit exceeded; the response may include retry-after.
  • 502 / 504: Upstream OCR provider error or timeout.

On this page