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, andaliyun. 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/recognizepath. - Authentication header:
Authorization: Bearer $TOS_API_KEY. Keys start withgk_. - scope:
ai:ocris required. Select it when creating the key; theai:*wildcard also works.
See Authentication.
Fields
| Field | Type | Required | Description |
|---|---|---|---|
image | file | Yes | Image or PDF file to recognize |
scene | string | No | Recognition scene, default general; options: general / document / receipt / idcard |
language | string | No | Recognition language, default zh-CN |
format | string | No | File format; inferred from the filename extension or MIME type when omitted |
- Supported formats:
png/jpg(jpegis normalized tojpg) /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 includeretry-after.502/504: Upstream OCR provider error or timeout.
Related pages
Speech Recognition (ASR) and Speech Synthesis (TTS)
OpenAI-compatible POST /v1/audio/transcriptions speech-to-text (multipart) and POST /v1/audio/speech text-to-speech (JSON).
Vision Segmentation (SAM3 Image/Video)
Image segmentation with POST /v1/vision-segment/predictions and video segmentation with /v1/vision-segment/video, powered by SAM3.