Skip to main content

Review Feature

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

Note

This feature is only available for V2 API endpoints.

Example

Nodejs
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 returned 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.

ParameterDescription
dataCorrected json response data in base64url encoded
signatureSignature 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")