GLAIR Vision Node.js SDK
You need Node version 18 or higher. For local development, we recommend to use Node Version Manager (NVM).
Install
npm install @glair/vision
The package needs to be configured with your credentials, see here for more details.
import { Vision } from "@glair/vision";
const vision = new Vision({
apiKey: "api-key",
username: "username",
password: "password",
});
Afterwards, you can use the provided functions to access GLAIR Vision API:
The SDK can be initialized with several options:
import { Settings } from "@glair/vision/lib/api/config";
const visionConfig: Settings = {
baseUrl: "https://api.vision.glair.ai",
apiVersion: "v1",
apiKey: "default-api-key",
username: "default-username",
password: "default-password",
};
Option | Default | Description |
---|---|---|
baseUrl |
https://api.vision.glair.ai |
Base URL for the API |
apiVersion |
v1 |
GLAIR Vision API version to be used |
apiKey |
default-api-key |
Your API Key |
username |
default-username |
Your username |
password |
default-password |
Your password |
You can override the configuration values for one-time only:
const resp = await vision.ocr
.ktp(
{ image: "/path/to/image.jpg" },
{ apiKey: "xxx", username: "yyy", password: "passwd" }
)
.catch((err) => console.error(err));
console.log(resp);
The second parameter is Partial<Settings>
(same as Settings
but all optional). It will be merged with the original Settings
you set when instantiating the Vision instance.
GLAIR Vision Node.js SDK is packaged with TypeScript declarations. You don't need to install another package.
Instantiate a Vision instance in a file and export it.
// util/vision.ts
import { Vision } from "@glair/vision";
const vision = new Vision({
apiKey: "api-key",
username: "username",
password: "password",
});
Then you can use the vision
object in server-side NextJS.
// api/ktp.ts
import { vision } from "../util/vision";
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const resp = await vision.ocr.ktp({
image: "/path/to/image.jpg",
});
res.status(200).json(resp);
}
- I got
ReferenceError: FormData is not defined
error. What should I do?- Make sure you use Node version 18 or higher.
const resp = await vision.ocr
.ktp({ image: "/path/to/image.jpg", qualities_detector: true }) // qualities_detector is false by default
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.ocr
.npwp({ image: "/path/to/image.jpg" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision
.kk({ image: "/path/to/image.jpg" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.ocr
.stnk({ image: "/path/to/image.jpg" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.ocr
.bpkb({ image: "/path/to/image.jpg" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.ocr
.passport({ image: "/path/to/image.jpg" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.ocr
.licensePlate({ image: "/path/to/image.jpg" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.ocr
.generalDocument({ image: "/path/to/image.jpg" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.ocr
.invoice({ image: "/path/to/image.jpg" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.ocr
.receipt({ image: "/path/to/image.jpg" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.faceBio
.match({
captured: "/path/to/captured.jpg",
stored: "/path/to/stored.jpg",
})
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.faceBio
.passiveLiveness({
image: "/path/to/image.jpg",
})
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.faceBio
.activeLiveness({
image: "/path/to/image.jpg",
gestureCode: "gesture-code",
})
.catch((err) => console.error(err));
console.log(resp);
Create session
const resp = await vision.faceBio.passiveLivenessSessions
.create({
success_url: "https://docs.glair.ai?success=true",
cancel_url: "https://docs.glair.ai?success=false",
})
.catch((err) => console.error(err));
console.log(resp);
Retrieve Session
const resp = await vision.faceBio.passiveLivenessSessions
.retrieve({ sid: "session-id" })
.catch((err) => console.error(err));
console.log(resp);
Create session
const resp = await vision.faceBio.activeLivenessSessions
.create({
success_url: "https://docs.glair.ai?success=true",
cancel_url: "https://docs.glair.ai?success=false",
number_of_gesture: 3,
})
.catch((err) => console.error(err));
console.log(resp);
Retrieve Session
const resp = await vision.faceBio.activeLivenessSessions
.retrieve({ sid: "session-id" })
.catch((err) => console.error(err));
console.log(resp);
Create session
const resp = await vision.ocr.ktpSessions
.create({
success_url: "https://docs.glair.ai?success=true",
cancel_url: "https://docs.glair.ai?success=false",
})
.catch((err) => console.error(err));
console.log(resp);
Retrieve Session
const resp = await vision.ocr.ktpSessions
.retrieve({ sid: "session-id" })
.catch((err) => console.error(err));
console.log(resp);
Create session
const resp = await vision.ocr.npwpSessions
.create({
success_url: "https://docs.glair.ai?success=true",
cancel_url: "https://docs.glair.ai?success=false",
})
.catch((err) => console.error(err));
console.log(resp);
Retrieve Session
const resp = await vision.ocr.npwpSessions
.retrieve({ sid: "session-id" })
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.identity
.verification({
nik: "1234567890123456",
name: "John Doe",
date_of_birth: "01-01-2000",
})
.catch((err) => console.error(err));
console.log(resp);
const resp = await vision.identity
.faceVerification({
nik: "1234567890123456",
name: "John Doe",
date_of_birth: "01-01-2000",
face_image: "/path/to/image.jpg",
})
.catch((err) => console.error(err));
console.log(resp);