Skip to content
Constaia

Next.js

Validate documents with AI in Next.js

A route handler receives the file, calls Constaia with the SDK and returns the verdict. The key stays on the server.

Install

npm i @constaia/sdk

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.

Full guide
app/api/verify/route.ts
import { Constaia } from "@constaia/sdk";

const constaia = new Constaia(); // reads CONSTAIA_API_KEY

export async function POST(request: Request) {
  const form = await request.formData();
  const file = form.get("file");
  if (!(file instanceof File)) return Response.json({ error: "missing_file" }, { status: 400 });

  const analysis = await constaia.analyze(file, {
    expect: "es_dni",
    checks: { notExpired: true },
    storage: "none",
  });

  return Response.json({
    status: analysis.verdict?.status, // "valid" | "invalid" | "review"
    reasons: analysis.verdict?.reasons,
  });
}

One call. An answer you can act on.

  1. 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.

  2. 02

    We read, classify and check

    OCR, AI classification and deterministic validators: PDF417 barcodes, MRZ, ABA routing numbers, dates and totals.

  3. 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.