Classify a document automatically
Sends a document image without declaring a template. The OCR identifies the document type and side, checks that it is in the allowed_templates list and then runs the same validations and extraction as sending with a template.
Use it when the user may send more than one document type — for example, a CNH or an RG — and you do not want to ask them to choose before the capture.
Endpoint
/imageThis is the same endpoint used to send with a template. The request body is what changes the behavior: send allowed_templates instead of template. The two fields are mutually exclusive — sending both, or neither, returns 400.
Authentication
Send the API key in the Authorization header. See Authentication.
Request body
| Field | Type | Required | Description | Size |
|---|---|---|---|---|
document_b64 | string | Yes | Document file in base64. JPEG, or a single-page PDF. | 3 MB (JPEG), 30 MB (PDF) |
allowed_templates | string[] | Yes | Document types you accept. Values in the Allowed templates table. | — |
{
"document_b64": "YOUR_BASE64_DOCUMENT",
"allowed_templates": ["cnh", "rg"]
}
import requests
response = requests.post(
"https://api.caas.qitech.app/ocr/image",
headers={"Authorization": "YOUR_API_KEY"},
json={
"document_b64": "YOUR_BASE64_DOCUMENT",
"allowed_templates": ["cnh", "rg"],
},
)
print(response.status_code, response.json())
Allowed templates
Send the whole document (cnh) to accept either side, or a specific side (cnh_front) to accept only that side.
| Value | Accepts |
|---|---|
cnh | Physical CNH (driver's license), front (cnh_front) or back (cnh_back). |
cnh_front, cnh_back | Only the given side of the physical CNH. |
cnh_digital | PDF of the digital CNH. |
rg | Physical RG or CIN (identity card), front (rg_front) or back (rg_back). |
rg_front, rg_back | Only the given side of the physical RG or CIN. |
cin_digital | PDF of the digital CIN. |
rg_digital | PDF of the digital RG. |
national_migration_registry | CRNM (national migration registry card), front or back. |
national_migration_registry_front, national_migration_registry_back | Only the given side of the CRNM. |
national_registry_of_foreigners | RNE (national registry of foreigners card), front or back. |
national_registry_of_foreigners_front, national_registry_of_foreigners_back | Only the given side of the RNE. |
Response
| Field | Type | Description |
|---|---|---|
ocr_key | uuid | Image key. Use it to reference the document in other QI Tech products. |
template | string | Identified template, always including the side when the document has two: cnh_front, rg_back, cnh_digital... |
is_inferred_template | boolean | true when the template was identified by automatic classification. |
allowed_templates | string[] | The list sent in the request. |
created_at | string | Processing date and time, in ISO 8601 (UTC). |
{
"ocr_key": "f1c0d2e1-f950-4360-896d-36588e443fc9",
"template": "cnh_front",
"is_inferred_template": true,
"allowed_templates": ["cnh", "rg"],
"created_at": "2026-10-16T13:45:12Z"
}
You can retrieve the image later by its ocr_key, as described in Sending a document.
Do not use real personal or company data in the sandbox environment.
Errors
Rejected document
When the image is processed but rejected, the response is 400 and includes the ocr_key of the attempt. title gives the category and reason the cause:
{
"title": "invalid",
"description": "The uploaded image cannot be successfully processed.",
"reason": "document_not_allowed",
"ocr_key": "f1c0d2e1-f950-4360-896d-36588e443fc9"
}
| Status | title | reason | When it happens |
|---|---|---|---|
| 400 | invalid | template_not_classified | The OCR did not recognize the document. |
| 400 | invalid | document_not_allowed | The document was recognized but is not in allowed_templates. |
| 400 | invalid | multiple_documents_found | There is more than one document in the image. |
| 400 | invalid | invalid_document | The image was not accepted as a valid document of the identified type. |
| 400 | invalid | missing_document_section | Part of the document is outside the image or covered. |
| 400 | invalid | missing_data | Required fields of the document could not be read. |
| 400 | invalid | qr_code_not_found | Digital PDF (CNH, RG or CIN) without a QR code. |
| 400 | invalid | not_digitally_signed | Digital PDF (CNH, RG or CIN) without the issuer's digital signature. |
| 400 | bad_quality | blurred_document | Blurred or low-quality image. JPEG only. |
| 400 | bad_quality | document_position_invalid | The document touches the edge of the image. JPEG only. |
| 400 | bad_quality | glare_on_document | Glare that hides or distorts information on the document. |
| 400 | bad_quality | color_irregularity | Irregular color distribution on the document. |
| 400 | bad_quality | face_not_found | No face detected in the document photo. |
| 400 | bad_quality | face_out_of_bounds | The face is partly outside the image. |
| 400 | bad_quality | face_brightness_problem | The face is too dark. |
| 400 | bad_quality | face_too_close | The face takes up too large an area of the image. |
| 400 | bad_quality | face_too_distant | The face takes up too small an area of the image. |
Face validation (face_*) applies only to the sides that carry a photo: CNH front, RG or CIN front, CRNM front and RNE back.
Refused request
These errors happen before processing and do not generate an ocr_key:
| Status | title | reason | When it happens |
|---|---|---|---|
| 400 | Invalid JSON | — | The request body is not valid JSON. |
| 400 | Request data failed validation | — | Body outside the contract: a required field is missing, an unknown field is sent, a value is outside the list, or template is sent together with allowed_templates. |
| 400 | Invalid base64 | invalid_base64 | document_b64 is not valid base64, or the file is neither JPEG nor PDF. |
| 400 | File is too big | max_file_size_exceeded | JPEG over 3 MB or PDF over 30 MB. |
| 400 | Document is too big | max_pages_exceeded | PDF with more than one page. |
| 401 | Authorization header not found | — | The Authorization header is missing. |
| 401 | Deactivated ApiKey | — | The API key has been deactivated. |
| 403 | Invalid ApiKey | — | The API key does not exist. |
| 500 | Internal Server Error | — | Internal failure. Try again later. |
Generic HTTP statuses are listed in HTTP status.