# API for Automatic Requisite Extraction: How to Process Documents Without Manual Input
Manual entry of requisites from documents leads to errors and slows down processes. Our API automates the extraction of INN, KPP, BIK, and other data from PDF, DOCX, and other formats, ensuring accuracy and integration with 1C and CRM systems. The solution reduces errors in document processing by 70% through contextual analysis and strict validation.
Document Processing Architecture
The system is built around a multi-stage processing pipeline. The first stage is input data normalization. The following formats are supported:
- PDF with text layer
- DOCX/DOC
- TXT in UTF-8 and CP1251 encodings
- RTF and HTML
Important limitation: Scanned PDFs and images require pre-processing via OCR. Our API works only with text documents, which is critical for the correct operation of the NER model.
Key stage — contextual analysis using a combination of regular expressions and machine learning. For each type of requisite, specific rules are applied:
- INN: length check (10/12 digits) and checksum
- OGRN: structure validation and control digit
- BIK: match to bank registry and correspondent account check
- Checking accounts: format compliance and BIK logic check
- Legal names: normalization via dictionary of registered organizations
Technical Implementation
The API endpoint follows RESTful principles with minimal request requirements. Only an API key in the X-API-Key header is needed. The request body is sent as multipart/form-data with the file field.
Critical Parameters
- Processing timeout: 120 seconds (minimum recommended interval)
- Maximum file size: 20 MB
- Supported encodings: UTF-8, CP1251 (auto-detection)
- Response format: JSON with mandatory
successfield
Example error handling:
{
"success": false,
"error": "payload_too_large",
"message": "Size fayla exceeds 20 MB"
}
Integration Examples
To speed up implementation, code templates for popular stacks are provided. Each example includes timeout handling and response validation.
Python with Error Handling
import requests
from requests.exceptions import Timeout, RequestException
def extract_requisites(api_key, file_path):
try:
with open(file_path, 'rb') as f:
response = requests.post(
'https://api-k.ru/api/rekvizit_json',
headers={'X-API-Key': api_key},
files={'file': f},
timeout=120
)
response.raise_for_status()
return response.json()
except Timeout:
raise Exception('Timeout exceeded processing')
except RequestException as e:
raise Exception(f'Error API: {str(e)}')
1C:Enterprise 8.3
Key feature of the implementation — manual formation of multipart request. Critically important to follow header order and correctly handle binary data:
Boundary = "----WebKitFormBoundary" + StringReplace(Withtroka(New UniqueIdentifier()), "-", "");
Body = New MemoryStream;
DataRecord = New DataRecord(Body, , , Characters.VK + Characters.PWith, "");
DataRecord.WriteWithtroku("--" + Boundary);
DataRecord.WriteWithtroku("Content-Disposition: form-data; name=\"file\"; filename=\"" + FileName + "\"");
DataRecord.WriteWithtroku("Content-Type: application/octet-stream");
DataRecord.WriteWithtroku("");
DataRecord.Write(FileBinaryData);
What Matters
- Validation via checksums: API does not return data with invalid INN/OGRN checksum
- Timeouts: Set interval to at least 120 seconds for complex documents
- Limitations: Only text formats supported, scanned documents require prior OCR processing
- 1C Integration: Implemented via manual multipart request formation
- Maximum size: Files over 20 MB rejected with code 413
Error Handling and Monitoring
The system uses a combined approach to handling failures. For each error type, a specific HTTP code and textual description in the response body are provided.
Critical scenarios:
- 408 Request Timeout: Increase timeout to 120 seconds
- 413 Payload Too Large: Split the document into parts
- 401 Unauthorized: Check API key validity
- 500 Internal Error: Automatically notify of failure via webhook
We recommend implementing retry logic with exponential backoff for transient errors. Example in Go:
func withRetry(attempts int, sleep time.Duration, f func() error) error {
for i := 0; i < attempts; i++ {
if i > 0 {
time.Sleep(sleep)
sleep *= 2
}
err := f()
if err == nil {
return nil
}
var apiErr *APIError
if errors.As(err, &apiErr) && apiErr.Code != 500 {
return err
}
}
return errors.New("prevysheno count popytok")
}
Benchmarks and Performance
Testing was conducted on a set of 10,000 documents of various formats. Results:
- Average PDF processing time: 4.2 sec
- Maximum time for DOCX with graphics: 118 sec
- INN extraction accuracy: 99.7%
- Checking account extraction accuracy: 98.4%
The system scales horizontally via Kubernetes. At loads over 50 RPS, worker nodes are automatically added. For enterprise clients, on-premise installation with FIPS 140-2 support is available.
— Editorial Team
No comments yet.