Language
TensorFusion Docs

OCR Text Recognition

POST /v1/recognize for image/PDF text recognition with multipart upload.

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 selects an available OCR capability for the request.

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.
  • Availability: current OCR capabilities are shown in the console and model catalog; callers do not need to know the internal implementation.

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 can vary slightly between runs, because the gateway routes each request according to your organization's policy. If your workflow depends on exact layout coordinates, validate the output on your side rather than assuming they are stable across requests.

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: OCR service unavailable or timed out.

On this page