Usage
To get Hautech AI key you need to create an application in the Developer Portal
To use API directly you need to create and sign a root token with your Hautech AI key.
This is a JavaScript example of how to do it:
const axios = require('axios');
const jwt = require('jsonwebtoken');
const options = {
appId: 'YOUR_APP_ID',
appKeyId: 'YOUR_APP_KEY_ID',
appKeySecret: 'YOUR_APP_KEY_SECRET',
};
const createPrivateKey = (key) => {
const header = `-----BEGIN PRIVATE KEY-----\n`;
const footer = `\n-----END PRIVATE KEY-----`;
const keyBody = key.match(/.{1,64}/g).join('\n');
return header + keyBody + footer;
};
const createToken = () => {
const payload = { iss: options.appId };
const privateKey = createPrivateKey(options.appKeySecret);
return jwt.sign(payload, privateKey, {
algorithm: 'RS256',
expiresIn: 3600,
keyid: options.appKeyId,
});
};
const token = createToken();
You need to pass the token in the Authorization
header of all of your requests.
Example
Using the token you can call the API endpoints.
For example, this is how to start an operation to generate an image:
const baseUrl = 'https://api.hautech.ai';
const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' };
const startOperation = async () => {
const imageResponse = await axios.post(`${baseUrl}/images`, { url: 'YOUR_IMAGE_URL' }, { headers });
const image = imageResponse.data;
const operationData = {
input: {
aspectRatio: '1:1',
modelId: '1',
productImageId: image.id,
prompt: 'Latina woman',
quality: 'low',
seed: 1432142038298797,
},
type: 'generate.v1',
};
const operationResponse = await axios.post(`${baseUrl}/operations`, operationData, { headers });
const operation = operationResponse.data;
console.log(operation);
};
startOperation();