Review feature

You can use the service review feature to validate the results during the service call.

Example

const axios = require("axios");

const api = "<API-V2>";
const headers = {
  "x-aigen-key": "<KEY>",
  "x-review-flow": true,   //Enable review feature
  "x-redirect-url": "https://example.com/callback",    //Review result will be retuen to your url 
  "x-review-expire": 3600  //Default 3600 sec
};
const data = { image: "<base64_string>" };

axios
  .post(api, data, { headers: headers })
  .then((res) => {
    console.log(res.data);
  })
  .catch((err) => {
    console.error(err.response.data);
  });

After calling the service, you will be given a URL to check the results

{
    ...,
    "links": {
        "review_url": "..."
    }
}

After submitting the review page will redirect to a page with parameters.

Parameters
Description

data

Corrected json response data in bas64url encoded

signature

Signature of data

Verifying signatures

To ensure that a request originates from AIGEN, it's important to verify its signature. This involves utilizing the HMAC-SHA256 algorithm with the API key.

  1. Using the HMAC-SHA256 algorithm with api key as the secret key.

  2. Compute the digest for the data.

  3. Confirm that the base64 encoded digest matches the received signature.

import base64
import hashlib
import hmac

API_KEY = '...'
received_signature = b'...'
received_data = b'...'

decoded_data = base64.urlsafe_b64decode(received_data)
hash = hmac.new(API_KEY.encode('utf-8'), decoded_data, hashlib.sha256).digest()
signature = base64.urlsafe_b64encode(hash).rstrip(b'=')
if signature == received_signature:
    print("signature verified")

Last updated