Aidge Resource
Try for freeWorkplace
  • LATEST ADVANCEMENTS
    • Introducing Marco-MT: Bringing Translation to the Next Level with LLM
  • GETTING STARTED
    • Quick Start
    • Account and Authentication
    • Your First API Request
    • Test Your API Requests
    • Service Level Agreement
    • FAQ
  • API REFERENCE
    • E-commerce Information Translation
      • Marco Translator
        • Marco Translator API Reference
      • Image Translation
        • Image Translation Pro Version API Reference
        • Image Translation Pro Version Result API Call Description
        • Image Translation Standard Version API Reference
    • E-commerce Image Editing
      • Image Background Removal
        • Image Background Removal API Reference
      • Image Upscaling
        • Image Upscaling API Reference
      • Image Cropping
        • Image Cropping API Reference
      • Image Elements Removal
        • Image Elements Removal API Reference
      • Image Elements Detection
        • Image Elements Detection API Reference
    • E-commerce Virtual Model
      • Virtual Model Alternation
        • Virtual Model Alternation Submit API Reference
        • Virtual Model Alternation Result Query API Reference
      • Virtual TryOn
        • Virtual Try-on Submit API Reference
        • Virtual Try-On Query API Reference
        • General Model Library Reference
      • Hands&Feet Repair
        • Hands&Feet Repair Submit API Reference
        • Hands&Feet Repair Query API Reference
    • Editor Documentation
      • AI Model Editor
      • AI Image Editor
        • Image Workbench
        • Background Removal
        • Elements Removal
        • Image Translation
Powered by GitBook
On this page
  • Download SDK
  • Sample Code

Was this helpful?

  1. GETTING STARTED

Your First API Request

Download the necessary SDK and start making your first API requests within Aidge.

Once you have successfully obtain your AccessKey and AccessKey Secret, now we can proceed to set up your first API call.

To begin, you will need to download our SDK, which is necessary for accessing our API and ensures that your access is authenticated.

It is recommended to invoke the services using the Java SDK. Aidge's SDK offers functionalities for API request encapsulation, digest signature, response parsing, and message listening. By utilizing this SDK, you can effortlessly make API calls, retrieve API results, and monitor real-time messages.

Download SDK

  1. Sign in and navigate to our page below to download the SDK

  2. Select the development language you require and download the corresponding SDK.

JAVA SDK
PYTHON SDK

Updated Time 2025-02-06

Updated Time 2023-10-23

Sample Code

Once you have obtained the SDK, below are some code examples for you to write up your first API request.

Here is a sample code to call our API ( using image cut-out api as an example):

IopClient client = new IopClientImpl("https://api.aidc-ai.com", "your key", "your secret");
IopRequest request = new IopRequest();
// Adding this trial tag in header means using the trial resource to test, 
// please remove this ##trial tag after you purchased the API
request.addHeaderParameter("x-iop-trial","true")
request.setApiName("/ai/image/cut/out");
request.addApiParameter("simplify", "true");
//adding parameters as in the api doc we provide etc. I only listed one for example
request.addApiParameter("backGroundType", "WHITE_BACKGROUND");
request.addApiParameter("targetHeight", "1000");
request.addApiParameter("targetWidth", "800");
request.addApiParameter("imageUrl", "https://ae01.alicdn.com/kf/Sa78257f1d9a34dad8ee494178db12ec8l.jpg");
IopResponse response = client.execute(request);
System.out.println(response.getBody());
import iop

client = iop.IopClient("https://api.aidc-ai.com", "your appKey", "your appSecret")
request = iop.IopRequest('/ai/image/cut/out')
request.set_protocol('GOP')
##Adding this trial tag in header means using the trial resource to test, please remove this ##trial tag after you purchased the API
request.add_header("x-iop-trial","true")
request.add_api_param('backGroundType', 'WHITE_BACKGROUND')
request.add_api_param('targetHeight', '1000')
request.add_api_param('targetWidth', '800')
request.add_api_param('imageUrl', 'https://ae01.alicdn.com/kf/Sa78257f1d9a34dad8ee494178db12ec8l.jpg')
response = client.execute(request)
print(response.type)
print(response.body)
package main

import (
	"bytes"
	"crypto/hmac"
	"crypto/sha256"
	"encoding/hex"
	"fmt"
	"io/ioutil"
	"net/http"
	"strings"
	"time"
)

func main() {
	// Your personal data
	accessKeyName := "your access key name" // e.g. 512345
	accessKeySecret := "your access key secret"
	apiName := "ai/image/cut/out"  // e.g. ai/text/translation/and/polishment
	apiDomain := "api.aidc-ai.com" // e.g. api.aidc-ai.com or cn-api.aidc-ai.com
	data := "{\"backGroundType\":\"WHITE_BACKGROUND\",\"targetHeight\":\"1000\",\"targetWidth\":\"800\",\"imageUrl\":\"https://ae01.alicdn.com/kf/Sa78257f1d9a34dad8ee494178db12ec8l.jpg\"}"

	// Basic URL (placeholders included)
	urlTemplate := "https://%s/rest/%s?partner_id=aidge&sign_method=sha256&sign_ver=v2&app_key=%s&timestamp=%s&sign=%s"

	// Timestamp in milliseconds
	timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/int64(time.Millisecond))

	// Calculate SHA256 HMAC
	h := hmac.New(sha256.New, []byte(accessKeySecret))
	h.Write([]byte(accessKeySecret + timestamp))
	sign := strings.ToUpper(hex.EncodeToString(h.Sum(nil)))

	// Create the final URL with real values
	finalURL := fmt.Sprintf(urlTemplate, apiDomain, apiName, accessKeyName, timestamp, sign)

	// Add "x-iop-trial": "true" for trial
	headers := map[string]string{
		"Content-Type": "application/json",
		"x-iop-trial": "true", // remove if not trial 
	}

	// Do HTTP POST request
	response, err := makeRequest("POST", finalURL, data, headers)
	if err != nil {
		fmt.Printf("Error making request: %s\n", err)
		return
	}
	fmt.Printf("Response: %s\n", response)
}

// makeRequest handles the HTTP request to the specified URL with the given data and headers
func makeRequest(method, url, data string, headers map[string]string) (string, error) {
	client := &http.Client{}
	req, err := http.NewRequest(method, url, bytes.NewBuffer([]byte(data)))
	if err != nil {
		return "", err
	}

	for key, value := range headers {
		req.Header.Set(key, value)
	}

	resp, err := client.Do(req)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}
	return string(body), nil
}
PreviousAccount and AuthenticationNextTest Your API Requests

Last updated 3 months ago

Was this helpful?

Download
Download