Express
Validate documents with AI in Express
multer in memory and the JavaScript SDK: the file never touches disk.
Install
npm i @constaia/sdk multer
The safe pattern
The browser or app never sees your secret key. The file goes to your server, your server calls Constaia and returns the verdict.
server.ts
import express from "express";
import multer from "multer";
import { Constaia } from "@constaia/sdk";
const app = express();
const upload = multer({ storage: multer.memoryStorage(), limits: { fileSize: 20 * 1024 * 1024 } });
const constaia = new Constaia();
app.post("/api/verify", upload.single("file"), async (req, res) => {
if (!req.file) return res.status(400).json({ error: "missing_file" });
const analysis = await constaia.analyze(req.file.buffer, {
filename: req.file.originalname,
expect: "es_dni",
checks: { notExpired: true },
});
res.json({ status: analysis.verdict?.status, reasons: analysis.verdict?.reasons });
});
app.listen(3000);One call. An answer you can act on.
- 01
Send the document and what you expect
Photo, screenshot or PDF. Set the expected type and the rules: not expired, under 6 months old, in this person's name.
- 02
We read, classify and check
European OCR, AI classification and deterministic validators: NIF letter, MRZ, IBAN, dates and totals.
- 03
Get the verdict and delete the file
valid, invalid or review with reasons in your language. By default the file is deleted when the analysis ends.
And for the record…
Create your account, copy the test key and validate your first document in five minutes.