Background supergraphic

GLAIR Vision SDK

Our SDK lets you make server-side HTTP requests from your server to GLAIR Vision API endpoints. It contains boilerplate code so you can get up and running in just a few lines of code..

Official libraries

Node.js

Node.js® is an open-source, cross-platform JavaScript runtime environment.

Read more

Java

Java is a widely-used programming language known for its versatility and robustness. Java is known for its "write once, run anywhere" principle

Read more

Go

Go is an open source programming language that makes it simple to build secure, scalable systems

Read more

iOS

iOS is Apple's mobile operating system for their line of smartphones and tablets.

Read more

Android

Android is Google's mobile operating system for their line of smartphones and tablets.

Read more

NodeJS SDK

Requires Node.js v18 or higher. More details on NPM page.

Installation

1
npm install @glair/vision

Usage

1
2
3
4
5
6
7
8
9
import { Vision } from '@glair/vision'; const vision = new Vision({ apiKey: 'api-key', username: 'username', password: 'password', }); await vision.ocr.ktp({ image: '/path/to/image/KTP.jpg' });

Usage (override Base URL)

1
2
3
4
5
6
7
8
9
10
11
12
import { Vision } from '@glair/vision'; // You can override baseUrl by passing "baseUrl" param. Default value is https://api.vision.glair.ai. // This is useful if you want to use our staging environment. const vision = new Vision({ baseUrl: 'https://api.vision.glair.ai', apiKey: 'api-key', username: 'username', password: 'password', }); await vision.ocr.ktp({ image: '/path/to/image/KTP.jpg' });

Java SDK

Requires Java 8 or higher. More details on Maven Page.

Requirement

  1. Requires Java 8 or higher.
  2. Valid GLAIR credentials, including an API key, username, and password.

Integration

Installation (build.gradle)

1
implementation 'ai.glair:glair-vision:0.0.1-beta.1'

Configuration

OptionDefaultDescription
apiKeydefault-api-keyYour API Key
usernamedefault-usernameYour username
passworddefault-passwordYour password
baseUrlhttps://api.vision.glair.aiBase URL for the API
apiVersionv1GLAIR Vision API version to be used

Utilizing SDK

Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import glair.vision.Vision; import glair.vision.model.VisionSettings; public class App { public static void main(String[] args) { VisionSettings settings = new VisionSettings.Builder() .username("username") .password("password") .apiKey("api-key") .build(); Vision vision = new Vision(settings); String imagePath = "/path/to/image.jpg"; String response = ""; try { KtpParam param = new KtpParam(imagePath); response = vision .ocr() .ktp(param); } catch (Exception e) { response = e.getMessage(); } System.out.println("Response: " + response); } }

Go SDK

Detailed information abou GLAIR Vision Go SDK is available on the repository page.

Requirement

  1. Go 1.18 or higher with Go Modules.
  2. Valid GLAIR credentials, including an API key, username, and password.

Integration

Install the SDK to your Go project by executing the following command:

Installation

1
go get -u github.com/glair-ai/glair-vision-go

or, you can directly import the required modules and let the Go toolchain to automatically resolve the dependencies

1
2
3
4
import ( "github.com/glair-ai/glair-vision-go" "github.com/glair-ai/glair-vision-go/client" )

Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main import ( "context" "encoding/json" "fmt" "log" "os" "github.com/glair-ai/glair-vision-go" "github.com/glair-ai/glair-vision-go/client" ) func main() { ctx := context.Background() config := glair.NewConfig("", "", "") client := client.New(config) file, _ := os.Open("path/to/image.jpg") result, err := client.Ocr.KTP(ctx, glair.OCRInput{ Image: file, }) if err != nil { log.Fatalln(err.Error()) } jsonResponse, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(jsonResponse)) }

Configuration

OptionDefaultDescription
BaseUrlhttps://api.vision.glair.aiBase URL for GLAIR Vision API
ApiVersionv1GLAIR Vision API version to be used
ClientDefault Go HTTP clientHTTP Client to be used when sending request to GLAIR Vision API
LoggerLeveledLogger with LevelNoneLogger instace to be used to log errors, information, or debugging messages

Android SDK

Requirement

  1. Android 7 (API Level 24) or above
  2. Valid GLAIR credentials, including an API key, username, and password.
  3. The VisionSDK.zip file provided by GLAIR.

Integration

  1. Extract VisionSDK.zip to ~/.m2/repository.
  2. Add the following line to the settings.gradle.kts file:
1
2
3
4
5
6
7
dependencyResolutionManagement { repositories { mavenLocal() ... } ... }
  1. Add the following line to the build.gradle.kts file:
1
2
3
4
dependencies { implementation("ai.glair:vision-android:0.0.1-beta.1") ... }

Configuration

Here are two configuration classes for Vision SDK:

  1. VisionConfiguration: for essential and common configuration.
  2. <Type>Customization: for defining specific customizations for each type of SDK.

Begin by configuring the SDK with the following parameters. Only apiKey, username, and password are required in the VisionConfiguration class. The rest is optional.

1
2
3
4
5
6
7
import ai.glair.vision.model.VisionConfiguration val config = VisionConfiguration.builder<KtpCustomization>() .apiKey("apiKey") .username("username") .password("password") .build()

VisionConfiguration Class

OptionDefaultDescription
apiKeydefault-api-keyYour API Key
usernamedefault-usernameYour username
passworddefault-passwordYour password
baseUrlhttps://api.vision.glair.aiBase URL for the API
apiVersionv1GLAIR Vision API version to be used
logLevelLogLevel.INFOSpecifies the level of logging output for the logger
languageLanguage.ENSupport English (EN) and Bahasa Indonesia (ID). Values stored in Language enum class
customizationDefaultDefaults tailored to each type of SDK customization

Utilizing KTP Activity

If you prefer not to create your own UI for capturing and reading KTP, use the following code:

Call Activity

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class MainActivity: AppCompatActivity() { private var activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> processResult(result) } private fun initializeSdk() { val customization = KtpCustomization.Builder() .backgroundColor("#222222") .captureButtonColor("#ff0000") .build() val config = VisionConfiguration.builder<KtpCustomization>() .apiKey(apiKey) .username(username) .password(password) .customization(customization) .build() val intent = Intent(this@MainActivity, KtpActivity::class.java).apply { putExtra(KtpActivity.CONFIGURATION, config) } activityResultLauncher.launch(intent) } private fun processResult(result: ActivityResult) { if (result.resultCode == KtpActivity.RESULT_CODE && result.data != null) { val resultData = result.data!!.getStringExtra(KtpActivity.RESULT_KEY) Log.i("Main App", "Main app here: $resultData") } } }

Call Fragment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class MainActivity : AppCompatActivity() { private lateinit var fragment: KtpFragment private lateinit var config: VisionConfiguration<KtpCustomization> override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivityTemplateBinding.inflate(layoutInflater) setContentView(binding.root) val customization = KtpCustomization.Builder() .backgroundColor("#222222") .captureButtonColor("#ff0000") .build() val config = VisionConfiguration.builder<KtpCustomization>() .apiKey("apiKey") .username("username") .password("password") .customization(customization) .build() addFragment() } private fun addFragment() { fragment = KtpFragment(config) { result -> Log.i("Main App", "Main app here: $result") } val transaction = supportFragmentManager.beginTransaction() transaction.replace(R.id.fragment_container, fragment, KtpFragment.TAG) transaction.commit() } }

KtpCustomization Class

OptionDefaultDescription
backgroundColor#1C1B1FBackground color in Hex String RGB format
fontColor#E6E1E5Font color in Hex String RGB format
fontSize1fFont size relative to current GLAIR size
backColor#E6E1E5Back color in Hex String RGB format
captureButtonColor#E6E1E5Capture button color in Hex String RGB format
imagePickerColor#E6E1E5Image Picker color in Hex String RGB format
flipCameraColor#E6E1E5Flip Camera color in Hex String RGB format
retryColor#1C1B1FRetry color in Hex String RGB format
checklistColor#10B982Checklist color in Hex String RGB format

Utilizing Liveness Activity

If you'd rather not create your own UI for Liveness Verification, use the following code:

Call Activity

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class MainActivity: AppCompatActivity() { private var activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> processResult(result) } private fun initializeSdk() { val customization = LivenessCustomization.Builder() .backgroundColor("#222222") .livenessCountdown(5) .build() val config = VisionConfiguration.builder<LivenessCustomization>() .apiKey(apiKey) .username(username) .password(password) .customization(customization) .build() val intent = Intent(this@MainActivity, LivenessActivity::class.java).apply { putExtra(LivenessActivity.CONFIGURATION, config) } activityResultLauncher.launch(intent) } private fun processResult(result: ActivityResult) { if (result.resultCode == LivenessActivity.RESULT_CODE && result.data != null) { val resultData = result.data!!.getStringExtra(LivenessActivity.RESULT_KEY) Log.i("Main App", "Main app here: $resultData") } } }

Call Fragment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class MainActivity : AppCompatActivity() { private lateinit var fragment: LivenessFragment private lateinit var config: VisionConfiguration<LivenessCustomization> override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivityTemplateBinding.inflate(layoutInflater) setContentView(binding.root) val customization = LivenessCustomization.Builder() .backgroundColor("#222222") .livenessCountdown(5) .build() val config = VisionConfiguration.builder<LivenessCustomization>() .apiKey("apiKey") .username("username") .password("password") .customization(customization) .build() addFragment() } private fun addFragment() { fragment = LivenessFragment(config) { result -> Log.i("Main App", "Main app here: $result") } val transaction = supportFragmentManager.beginTransaction() transaction.replace(R.id.fragment_container, fragment, LivenessFragment.TAG) transaction.commit() } }

LivenessCustomization Class

OptionDefaultTypeDescription
backgroundColor#1C1B1FStringBackground Color
fontColor#E6E1E5StringForeground Color
fontSize1fFloatRelative Multiplier for Font Size Based on Current Size
backColor#E6E1E5StringButton Back Color
livenessNumberGesture1IntNumber of Gestures Needed
progressBarColor#E6E1E5StringProgress Bar Color
gestureIllustrationColor#E6E1E5StringGesture Illustration Color Below Camera View
livenessCountdown5IntTotal Countdown Time

Leveraging the Vision API Wrapper

If you prefer to build your own custom UI for capturing and processing Vision API data, you can use our Java API Wrapper.

iOS SDK

Requirement

  1. iOS 13 or higher.
  2. The VisionSDK.xcframework framework provided by GLAIR.
  3. Valid GLAIR credentials, including an API key, username, and password.

Integration

  1. Drag and drop the VisionSDK.xcframework folder into the Frameworks group in your Xcode project's navigator.
  2. Make sure the VisionSDK.xcframework is set to "Embed & Sign" in the Frameworks, Libraries, and Embedded Content section of your app's target settings.

Configuration

Begin by configuring the SDK with the following params. Only apiKey, username, and password are required. The rest is optional.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import VisionApp let config = VisionConfig( apiKey: "apiKey", username: "username", password: "password", baseUrl: "https://your-be-url", apiVersion: "v1", livenessNumberGesture: 2, livenessCountdown: 3, language: "id", backgroundColor: "FFFFFF", fontColor: "000000", fontSize: 16, captureButtonColor: "FF0000" ) VisionApp.sharedInstance.configure(config)
OptionDefaultDescription
apiKeydefault-api-keyYour API Key
usernamedefault-usernameYour username
passworddefault-passwordYour password
baseUrlhttps://api.vision.glair.aiBase URL for the API
apiVersionv1GLAIR Vision API version to be used
livenessNumberGesture3Number of gesture in Liveness SDK (Min: 1, Max: 3)
livenessCountdown3Countdown in Liveness SDK (Min: 3, Max: 5)
languageenSupport English (en) and Bahasa Indonesia (id)
backgroundColor#000000Background color in RGB or RGBA format
fontColor#FFFFFFFont color in RGB or RGBA format
fontSize17Font size
captureButtonColor#FFFFFFCapture button color in RGB or RGBA format

Utilizing KTP View Controller

If you prefer not to create your own UI for capturing and reading KTP, use the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Set close app callback for navigation VisionApp.sharedInstance.setCloseAppCallback { presentationMode.wrappedValue.dismiss() } // Utilize the GLAIR Vision KTP UIViewController: let viewController = VisionApp.sharedInstance.ktpView({ result in // get result properties: ktp result, captured image, and error }) // Utilize the GLAIR Vision Liveness UIViewController: let viewController = VisionApp.sharedInstance.livenessView({ result in // get result properties: success and response histories })

Leveraging the OCR KTP API Wrapper

If you'd rather create your own UI from scratch for capturing and reading KTP, you can use our API wrapper:

1
2
3
4
5
6
// OCR KTP let ktp = try await VisionApp.sharedInstance.ktp(imageData) // Liveness let activeLiveness = try await VisionApp.sharedInstance.activeLiveness(imageData, gestureCode) let passiveLiveness = try await VisionApp.sharedInstance.passiveLiveness(imageData)