API Retec OCR
Gọi Retec OCR từ phần mềm của bạn: gửi ảnh hoặc PDF, nhận lại toàn bộ văn bản, kèm các thông tin bạn cần lấy ra.
1. Nhận key
- Mỗi email một key, 5 lượt mỗi ngày (đặt lại lúc 0 giờ, giờ Việt Nam), tính riêng với lượt dùng trên trang web. Mỗi mạng (IP) còn có trần chung cho mọi key và lượt dùng trên web.
- Key được gửi tới email bạn nhập, không hiện trên trang này.
- Mất hoặc lộ key: đăng ký lại bằng chính email đó để nhận key mới, key cũ hết hiệu lực ngay. Hạn mức vẫn tính theo email.
Retec OCR API
Call Retec OCR from your software: send an image or PDF and get back the full text, plus the information you need extracted.
1. Get a key
- One key per email, 5 requests per day (resets at midnight, Vietnam time), counted separately from use on the website. Each network (IP) also has a shared cap across all keys and website use.
- The key is sent to the email you enter; it is never shown on this page.
- Lost or leaked key: sign up again with the same email to get a new key; the old key stops working immediately. The limit still counts per email.
2. Gọi API
POST https://ocr.retec.vn/api/v1/ocr, body multipart/form-data, key trong header Authorization: Bearer <key>.
| Trường | Bắt buộc | Mô tả |
|---|---|---|
file | Có | PDF hoặc ảnh JPG, PNG, WEBP, TIFF, BMP; tối đa 10 MB, PDF tối đa 10 trang. |
fields | Không | Các thông tin cần trích xuất, cách nhau bằng dấu phẩy hoặc xuống dòng, ví dụ Số văn bản, Ngày ban hành, Người ký. Tối đa 20 thông tin, 500 ký tự. Bỏ trống để chỉ lấy văn bản. |
lang | Không | Ngôn ngữ của tài liệu: vi tiếng Việt (mặc định), en tiếng Anh, auto tự động khi tài liệu có cả tiếng Việt và tiếng Anh (chậm hơn một chút). |
curl
curl -X POST https://ocr.retec.vn/api/v1/ocr \ -H "Authorization: Bearer $RETEC_API_KEY" \ -F "[email protected]" \ -F "fields=Số văn bản, Ngày ban hành, Người ký"
Python
import os, requests
with open("cong-van.pdf", "rb") as f:
r = requests.post(
"https://ocr.retec.vn/api/v1/ocr",
headers={"Authorization": f"Bearer {os.environ['RETEC_API_KEY']}"},
files={"file": f},
data={"fields": "Số văn bản, Ngày ban hành, Người ký"},
timeout=120,
)
data = r.json()
print(data["text"] if data["ok"] else data["message"])
3. Kết quả
Luôn là JSON. Thành công (HTTP 200):
{
"ok": true,
"text": "ỦY BAN NHÂN DÂN ...",
"pages": 2,
"fields": {"Số văn bản": "12/QĐ-UBND", "Ngày ban hành": "05/01/2026", "Người ký": "Nguyễn Văn A"},
"remaining": 4
}
fieldslànullkhi không gửifields; thông tin không tìm thấy có giá trị rỗng hoặc không có trong kết quả. Ngày tháng ở dạngDD/MM/YYYY.- Có
fieldsErrorkhi không trích xuất được thông tin: lượt vẫn tính,textvẫn đầy đủ. remaining: số lượt còn lại hôm nay của key.
Lỗi (HTTP 4xx, 5xx): {"ok": false, "code": "quota", "message": "…"}. message là câu có thể hiện cho người dùng, tiếng Việt hoặc tiếng Anh theo header Accept-Language (en → tiếng Anh); phần mềm nên xử lý theo code.
4. Mã lỗi
| code | HTTP | Ý nghĩa |
|---|---|---|
api_key | 401 | Thiếu key, key sai hoặc đã được thay bằng key mới. |
banned | 403 | Key hoặc mạng bị tạm khoá do sử dụng bất thường. |
country | 403 | Yêu cầu không đến từ Việt Nam. |
ipcheck | 503 | Chưa xác minh được mạng gửi yêu cầu, thử lại sau ít phút. |
quota | 429 | Key đã dùng hết lượt hôm nay. |
net_quota | 429 | Mạng của bạn đã dùng hết lượt hôm nay (tính chung mọi key và lượt dùng trên web). |
global | 429 | Hệ thống đã đạt giới hạn xử lý hôm nay. |
rate, inflight | 429 | Gọi quá nhanh, hoặc mạng của bạn đang có một file chưa xử lý xong. |
busy | 503 | Hệ thống đang bận, thử lại sau ít phút. |
type, empty, bad_file | 400 | Định dạng không hỗ trợ, file rỗng, hỏng, có mật khẩu hoặc quá số trang. |
too_large | 413 | File vượt quá dung lượng cho phép. |
fields | 400 | Danh sách thông tin quá dài hoặc quá nhiều mục. |
slow | 408 | Tải file lên quá chậm. |
error | 500 | Lỗi khi xử lý; lượt thường không bị tính. |
5. Giới hạn và lưu ý
- Chỉ nhận yêu cầu từ mạng tại Việt Nam: máy chủ gọi API cần đặt ở Việt Nam.
- Mỗi mạng (IP) chỉ một yêu cầu đang xử lý tại một thời điểm, tối đa 6 yêu cầu mỗi phút: gửi file lần lượt, chờ kết quả rồi gửi tiếp.
- Mỗi file thường mất vài giây; đặt thời gian chờ phía bạn khoảng 120 giây.
- Giữ key bí mật, chỉ gọi API từ máy chủ của bạn, không đặt key trong mã chạy trên trình duyệt hay ứng dụng phát hành.
- File và nội dung chỉ được xử lý trong bộ nhớ, không lưu lại, như trên trang web (xem Chính sách & Điều khoản).
- Kết quả được tạo tự động và có thể sai sót; hãy kiểm tra lại trước khi dùng cho việc quan trọng.
2. Call the API
POST https://ocr.retec.vn/api/v1/ocr, body multipart/form-data, key in the header Authorization: Bearer <key>.
| Field | Required | Description |
|---|---|---|
file | Yes | PDF or a JPG, PNG, WEBP, TIFF, BMP image; up to 10 MB, PDFs up to 10 pages. |
fields | No | The information to extract, separated by commas or new lines, e.g. Invoice number, Issue date, Signer. Up to 20 items, 500 characters. Leave empty to get the text only. |
lang | No | Document language: vi Vietnamese (default), en English, auto automatic for documents with both Vietnamese and English (slightly slower). |
curl
curl -X POST https://ocr.retec.vn/api/v1/ocr \ -H "Authorization: Bearer $RETEC_API_KEY" \ -H "Accept-Language: en" \ -F "[email protected]" \ -F "lang=en" \ -F "fields=Invoice number, Issue date, Signer"
Python
import os, requests
with open("invoice.pdf", "rb") as f:
r = requests.post(
"https://ocr.retec.vn/api/v1/ocr",
headers={"Authorization": f"Bearer {os.environ['RETEC_API_KEY']}", "Accept-Language": "en"},
files={"file": f},
data={"lang": "en", "fields": "Invoice number, Issue date, Signer"},
timeout=120,
)
data = r.json()
print(data["text"] if data["ok"] else data["message"])
3. Response
Always JSON. Success (HTTP 200):
{
"ok": true,
"text": "INVOICE ...",
"pages": 2,
"fields": {"Invoice number": "INV-0012", "Issue date": "05/01/2026", "Signer": "John Smith"},
"remaining": 4
}
fieldsisnullwhen you do not sendfields; information that is not found has an empty value or is missing from the result. Dates useDD/MM/YYYY.fieldsErroris present when the information could not be extracted: the request still counts andtextis still complete.remaining: the key's remaining requests for today.
Errors (HTTP 4xx, 5xx): {"ok": false, "code": "quota", "message": "…"}. message is a sentence you can show to users, in Vietnamese or English depending on the Accept-Language header (en → English); your software should act on code.
4. Error codes
| code | HTTP | Meaning |
|---|---|---|
api_key | 401 | The key is missing, wrong, or has been replaced by a new key. |
banned | 403 | The key or network is temporarily blocked due to unusual usage. |
country | 403 | The request does not come from Vietnam. |
ipcheck | 503 | The sending network could not be verified yet; try again in a few minutes. |
quota | 429 | The key has used all of today's requests. |
net_quota | 429 | Your network has used all of today's requests (all keys and website use combined). |
global | 429 | The system has reached today's processing limit. |
rate, inflight | 429 | Calls are too fast, or your network still has a file being processed. |
busy | 503 | The system is busy; try again in a few minutes. |
type, empty, bad_file | 400 | Unsupported format, or the file is empty, damaged, password-protected or has too many pages. |
too_large | 413 | The file exceeds the allowed size. |
fields | 400 | The list of information is too long or has too many items. |
slow | 408 | The upload is too slow. |
error | 500 | Processing error; the request is usually not counted. |
5. Limits and notes
- Requests are only accepted from networks in Vietnam: the server calling the API must be located in Vietnam.
- Each network (IP) can have only one request in progress at a time, and at most 6 requests per minute: send files one by one and wait for each result.
- Each file usually takes a few seconds; set your client timeout to about 120 seconds.
- Keep the key secret: call the API only from your own server, never put the key in code that runs in a browser or in a published app.
- Files and their content are processed in memory only and are not kept, just like on the website (see Policy & Terms).
- Results are generated automatically and may contain mistakes; check them before using them for anything important.