Skip to main content

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​

ENDPOINT
/image
METHOD
POST
STATUS
200

This 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​

FieldTypeRequiredDescriptionSize
document_b64stringYesDocument file in base64. JPEG, or a single-page PDF.3 MB (JPEG), 30 MB (PDF)
allowed_templatesstring[]YesDocument 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.

ValueAccepts
cnhPhysical CNH (driver's license), front (cnh_front) or back (cnh_back).
cnh_front, cnh_backOnly the given side of the physical CNH.
cnh_digitalPDF of the digital CNH.
rgPhysical RG or CIN (identity card), front (rg_front) or back (rg_back).
rg_front, rg_backOnly the given side of the physical RG or CIN.
cin_digitalPDF of the digital CIN.
rg_digitalPDF of the digital RG.
national_migration_registryCRNM (national migration registry card), front or back.
national_migration_registry_front, national_migration_registry_backOnly the given side of the CRNM.
national_registry_of_foreignersRNE (national registry of foreigners card), front or back.
national_registry_of_foreigners_front, national_registry_of_foreigners_backOnly the given side of the RNE.

Response​

FieldTypeDescription
ocr_keyuuidImage key. Use it to reference the document in other QI Tech products.
templatestringIdentified template, always including the side when the document has two: cnh_front, rg_back, cnh_digital...
is_inferred_templatebooleantrue when the template was identified by automatic classification.
allowed_templatesstring[]The list sent in the request.
created_atstringProcessing 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.

Important

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"
}
StatustitlereasonWhen it happens
400invalidtemplate_not_classifiedThe OCR did not recognize the document.
400invaliddocument_not_allowedThe document was recognized but is not in allowed_templates.
400invalidmultiple_documents_foundThere is more than one document in the image.
400invalidinvalid_documentThe image was not accepted as a valid document of the identified type.
400invalidmissing_document_sectionPart of the document is outside the image or covered.
400invalidmissing_dataRequired fields of the document could not be read.
400invalidqr_code_not_foundDigital PDF (CNH, RG or CIN) without a QR code.
400invalidnot_digitally_signedDigital PDF (CNH, RG or CIN) without the issuer's digital signature.
400bad_qualityblurred_documentBlurred or low-quality image. JPEG only.
400bad_qualitydocument_position_invalidThe document touches the edge of the image. JPEG only.
400bad_qualityglare_on_documentGlare that hides or distorts information on the document.
400bad_qualitycolor_irregularityIrregular color distribution on the document.
400bad_qualityface_not_foundNo face detected in the document photo.
400bad_qualityface_out_of_boundsThe face is partly outside the image.
400bad_qualityface_brightness_problemThe face is too dark.
400bad_qualityface_too_closeThe face takes up too large an area of the image.
400bad_qualityface_too_distantThe 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:

StatustitlereasonWhen it happens
400Invalid JSON—The request body is not valid JSON.
400Request 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.
400Invalid base64invalid_base64document_b64 is not valid base64, or the file is neither JPEG nor PDF.
400File is too bigmax_file_size_exceededJPEG over 3 MB or PDF over 30 MB.
400Document is too bigmax_pages_exceededPDF with more than one page.
401Authorization header not found—The Authorization header is missing.
401Deactivated ApiKey—The API key has been deactivated.
403Invalid ApiKey—The API key does not exist.
500Internal Server Error—Internal failure. Try again later.

Generic HTTP statuses are listed in HTTP status.