Übersicht

Vance AI bietet eine Suite aus einfachen und flexiblen API-Endpunkten an, die es Ihnen ermöglichen, unseren AI-Bildverarbeitungsfeatures in Ihre App oder Ihrem Workflow zu integrieren.

Authentifizierung

Die Vance AI API benötigt eine Authentifizierung durch einen API-Token, der innerhalb des Vance AI Accounts generiert wurde. Sie können den API-Token in dem Tab API Info auf der Seite Mein Account finden.

Alle Methoden in der Vance AI API benötigen eine Authentifizierung durch einen API-Token.

Zeigen Sie Ihren API-Token nicht öffentlich

Der API-Token sollte niemals öffentlich gezeigt werden, zum Beispiel in Ihrer Software/Anwendung oder auf Ihrer Webseite, da dies Nutzern den Zugang zu allen hier authentifizierten API-Dokumenten geben würde und Sie dies Ihre Credits kosten kann.

General

Response Success Example


HTTP/1.1 200 OK
{
    "code":200,
    "data":{
        "uid":"a56b7626da85dcd0fc68b91bc49b725d"
    }
}

Response Error Example


HTTP/1.1 200 OK
{
    "code": 10001, 
    "msg": "Illegal Parameter"
}

Upload

POST  https://api.vance.ai/web_api/v1/upload

Parameters:

Field Type Description
api_token string Your API token
file file Image file object

Error Codes:

Code Type Description
10001 number Illegal parameter
10010 number Internal error

Response Success Example:


{
    "code": 200,
    "data": {
        "uid": "b0c5b210dd1a698d0554bca3d1bdd7b4" // ID of Uploaded file
    }
}

Upload Demo:

PHP


post("https://api.vance.ai/web_api/v1/upload", [
    'multipart' => [
        [
            'name' => 'api_token',
            'contents' => '{{YOUR_API_KEY}}',
        ],
        [
            'name' => 'file',
            'contents' => fopen('{{YOUR_FILE_PATH}}', 'r'),
        ]
    ]
]);

echo $res->getBody()->getContents();
?>

Python


# Requires "requests" to be installed (see python-requests.org)
import requests
response = requests.post(
    'https://api.vance.ai/web_api/v1/upload',
    files={'file': open('{SOURCE_IMAGE_FILE_PATH}', 'rb')},
    data={'api_token': '{YOUR_API_TOKEN}'},
)
r = response.json()
if r['code'] == 200:
   print('uid:', r['data']['uid'])
else:
    print("Error:", r['code'], r['msg'])

JavaScript


import axios from 'axios'

let formData = new FormData()
formData.append('api_token', '{YOUR_API_TOKEN}');
formData.append('file', e.target.file[0]);
const config = {
    headers: {
        'Content-Type': 'multipart/form-data'
    }
}
return axios.post(
    'https://api.vance.ai/web_api/v1/upload', formData, config
).then(function (response)){
    if (response.status === 200 && response.data.code==200) {
        console.log('Success');
    }else{
        console.log('Error');
    }
})

Transform

POST  https://api.vance.ai/web_api/v1/transform

Parameters:

Field Type Description
api_token string Your API token
uid string ID of uploaded file
jconfig string Transform parameter in json format (Required)

Error Codes:

Code Type Description
10001 number Illegal parameter
10010 number Internal error, please contact administrator.
10011 number File doesn't exist
10012 number Job exceeds limitation
10013 number jparam parse error
10014 number Job failed and exited for unexpected reason

Response Success Example:


 HTTP/1.1 200 OK
{
    "code": 200,
    "data": {
        "trans_id": "fe854a3b20237f70d1efb757b6aa0cc4", //Transform Job ID
        "status": "finish", //waiting, finish, fatal, process
        "content": "finished, process time = 0.34204" //Processing details
    }
}

Transform Demo:

PHP


$http_client = new \GuzzleHttp\Client([
    'base_uri' => 'https://api.vance.ai',
    'verify'  => false,
]);

$json_string = file_get_contents("{{enlarge.json}}");
$json_string = trim($json_string,chr(239).chr(187).chr(191));

$response = $http_client->request('POST','/web_api/v1/transform', [
    'form_params' => [
        'api_token' =>  '91211a6f841cabdaa5353a67176e0507',
        'uid' => 'c6b3ae488e47a4e9495a1e5ed6d0c401',
        'jconfig' => $json_string,
    ]
]);

echo $response->getBody()->getContents();

Python


import requests
import json

jparam={}
with open(json_path, 'rb') as f:
    jparam = json.load(f)
    
data={
    'uid': '{uid_getted_from_upload_api}',
    'jconfig': json.dumps(jparam),
    'api_token': '{YOUR_API_TOKEN}'
    }
response = requests.post(
    'https://api.vance.ai/web_api/v1/transform',
     data)
r = response.json()
if r['code'] == 200:
    print('uid:', r['data']['trans_id'])

JavaScript


const servers = {
    service: 'https://api.vance.ai'
}

function start(uid, config) {
  const jconfig = require('@/static/json/infer/enlarge.json')
  jconfig.config.module_params.scale = config.scale + 'x'
  jconfig.config.module_params.suppress_noise = config.suppressNoise ? 26 : 0
  jconfig.config.module_params.remove_blur = config.removeBlur ? 26 : 0

  const params = {
    uid,
    jconfig: JSON.stringify(jconfig),
    api_token: '{YOUR_API_TOKEN}',
  }
  return axios.post(servers.service + '/web_api/v1/transform', params)
}

Download

GET | POST  https://api.vance.ai/web_api/v1/download

Parameters:

Field Type Description
api_token string Your API token
trans_id string Job ID

Error Codes:

Code Type Description
10001 number Illegal parameter
10010 number Internal error, please contact administrator.
10011 number Invalid download link

Download Demo:

PHP


$remoteFileUrl = 'https://api.vance.ai/web_api/v1/download?trans_id={trans_id_getted_from_transform_api}&api_token={YOUR_API_TOKEN}';

$ch = curl_init();
$timeout = 60;
curl_setopt($ch, CURLOPT_URL, $remoteFileUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$img = curl_exec($ch);
curl_close($ch);

$fp2 = @fopen('{{save_to_file_path}}', 'a');
fwrite($fp2, $img);
fclose($fp2);

Python


remoteFileUrl = 'https://api.vance.ai/web_api/v1/download?trans_id={trans_id_getted_from_transform_api}&api_token={YOUR_API_TOKEN}';
dst_path = 'C:/test.jpg'

response = requests.get(remoteFileUrl, stream=True)

f = open(dst_path, "wb")
for chunk in response.iter_content(chunk_size=512):
    if chunk:
        f.write(chunk)
f.close()

JavaScript


function download(transId) {
  const params = {
    trans_id: transId,
    api_token: '{YOUR_API_TOKEN}',
  }
  return axios({
    url: servers.service + '/web_api/v1/download',
    method: 'POST',
    data: params,
    responseType: 'blob',
  }).then((res) => {
    res = res.data
    if (
      !Object.prototype.hasOwnProperty.call(res, 'statusCode') &&
      !Object.prototype.hasOwnProperty.call(res, 'code')
    ) {
      const blob = new Blob([res], { type: 'application/image' })
      const downloadUrl = window.URL.createObjectURL(blob)
      const anchor = document.createElement('a')
      anchor.href = downloadUrl
      anchor.download = '2.jpg'
      anchor.click()
      window.URL.revokeObjectURL(blob)
    }
  })
}

Config Files

Click here to download the config files.