Recipes
Ready-to-use Rekognita integration examples for common tasks. Each recipe includes complete code that you can copy and adapt for your project.
Bulk Document Recognition
If you need to process a large number of documents — use batch submission with parallel requests:
import asyncio
from rekognita import AsyncClient
async def process_batch(files: list[str]):
client = AsyncClient(api_key="YOUR_API_KEY")
tasks = [
client.documents.create(
file=open(f, "rb"),
language="en"
)
for f in files
]
results = await asyncio.gather(*tasks)
for r in results:
print(f"{r.id}: {r.status}")
asyncio.run(process_batch([
"invoice_1.pdf",
"invoice_2.pdf",
"invoice_3.pdf",
]))Tip: Limit concurrency to 10 requests at the same time, so as not to exceed the rate limit.
Integration with Google Sheets
Automatically write recognition results to a Google Sheet via the Google Sheets API:
const { Rekognita } = require('@rekognita/sdk');
const { google } = require('googleapis');
const rekognita = new Rekognita({ apiKey: process.env.REKOGNITA_API_KEY });
// 1. Recognize the document
const doc = await rekognita.documents.create({
file: fs.createReadStream('receipt.jpg'),
language: 'en',
});
// 2. Wait for the result
const result = await rekognita.documents.waitForResult(doc.id);
// 3. Write to Google Sheets
const sheets = google.sheets({ version: 'v4', auth });
await sheets.spreadsheets.values.append({
spreadsheetId: 'YOUR_SHEET_ID',
range: 'A:C',
valueInputOption: 'RAW',
requestBody: {
values: [[result.text, result.confidence, new Date().toISOString()]]
}
});Webhook Processing with Express
Configure your server to receive results via webhooks:
const express = require('express');
const app = express();
app.use(express.json());
app.post('/webhooks/rekognita', (req, res) => {
const { document_id, status, result } = req.body;
if (status === 'completed') {
console.log(`Document ${document_id} processed!`);
console.log(`Text: ${result.text}`);
console.log(`Confidence: ${result.confidence}`);
// Save the result to your database
// await db.documents.update(document_id, { text: result.text });
}
res.sendStatus(200);
});
app.listen(3000);Do not forget to provide your webhook URL when creating a document via the
webhook_url parameter. More details in the Webhooks section.