Fast, accurate OCR extraction for document types using Google Gemini 2.5 Flash Lite. Optimized for speed with 1-2 second response times.
- π High-Speed OCR: Optimized for 1-2 second response times
- π Multi-Document Support: NID, BO Certificate, TIN Certificate, Bank Statements
- π€ AI-Powered: Google Gemini 2.5 Flash Lite with custom prompts
- π§ Smart Processing: Automatic image optimization and compression
- β‘ Performance Optimized: Concurrent request handling and deduplication
- π Type-Safe: Full TypeScript support with strict typing
- π Auto-Validation: Built-in response validation for each document type
- π API Documentation: Interactive Swagger UI at
/api
| Document Type | Fields Extracted |
|---|---|
| NID | name, date_of_birth, nid_number |
| BO | bo_id (16 digits) |
| TIN | tin_number (12 digits) |
| BANK | account_number, routing_number |
- Node.js: 18+
- NPM: 8+
- Google Gemini API Key: Get it here
git clone <repository-url>
cd ocr-global-api
npm installCreate a .env file in the root directory:
PORT=6060
GEMINI_API_KEY=your_gemini_api_key_here# Development mode (with hot reload)
npm run start:dev
# Production mode
npm run start:prod
# Standard development
npm run startThe server will start at http://localhost:6060
Interactive Swagger UI available at: http://localhost:6060/api
POST /api/ocr
curl -X POST http://localhost:6060/api/ocr \
-H "Content-Type: multipart/form-data" \
-F "file=@document.jpg" \
-F "type=NID"- Images: JPG, PNG, WebP, BMP, TIFF
- Documents: PDF
- Max Size: 10MB
NID- National ID CardBO- BO CertificateTIN- TIN CertificateBANK- Bank Statement
{
"type": "NID",
"details": {
"name": "John Doe",
"date_of_birth": "01/01/1990",
"nid_number": "1234567890123"
}
}{
"type": "NID",
"details": {}
}# Run unit tests
npm run test
# Run e2e tests
npm run test:e2e
# Test coverage
npm run test:cov
# Test with watch mode
npm run test:watch- β‘ Sub-2 Second Response: Optimized prompts and model parameters
- π Concurrent Processing: Handles multiple requests efficiently
- π¦ Smart Caching: Deduplicates identical requests
- πΌοΈ Image Optimization: Automatic compression (800x800, 75% quality)
- π― Direct API Calls: No streaming overhead for maximum speed
src/
βββ common/
β βββ prompts/ # Optimized AI prompts
β βββ utils/ # Image optimization utilities
βββ ocr/
β βββ dto/ # Request/response types
β βββ enums/ # Document type enums
β βββ ocr-helpers.ts # Pure utility functions
β βββ ocr.service.ts # Core OCR logic
β βββ ocr.controller.ts # API endpoints
βββ main.ts # Application bootstrap
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
GEMINI_API_KEY |
Google Gemini API key | Required |
- Model:
gemini-2.5-flash-lite - Temperature:
0(deterministic) - Max Output Tokens:
256 - Response Format: JSON with schema validation
1. "API Key not found"
# Ensure .env file exists and contains:
GEMINI_API_KEY=your_actual_api_key2. "Port already in use"
# Change port in .env file:
PORT=60603. "File too large"
- Max file size: 10MB
- Supported formats: JPG, PNG, WebP, BMP, TIFF, PDF
4. "Empty response"
- Ensure document text is clear and readable
- Check document type matches the
typeparameter - Verify image quality is sufficient
# Lint code
npm run lint
# Fix lint issues
npm run lint:fix
# Format code
npm run format# Build for production
npm run build
# Start built version
npm run start:prodThis project is MIT licensed.