All Products
Document Center

Artificial Intelligence Recommendation:SDK for Go

Last Updated:Mar 30, 2021

SDK for Go


To use AIRec SDK for Go, perform the following steps:

Step 1: Create an Alibaba Cloud account

For more information, see Sign up with Alibaba Cloud. We recommend that you complete real-name verification at your earliest opportunity. Otherwise, you cannot use some Alibaba Cloud services.

Step 2: Obtain an Alibaba Cloud AccessKey pair

Before you use AIRec SDK for Java, you must apply for an Alibaba Cloud AccessKey pair.

Go to the Security Management page. Select an AccessKey pair for AIRec SDK for Java. The AccessKey pair consists of an AccessKey ID and an AccessKey secret. If no AccessKey pair is available, create one and make sure that it is in the Enable state. For more information about how to create an AccessKey pair, see Preparations.

Step 3: Install the Go development environment

We recommend that you use Go 1.5 or later for AIRec SDK. You can visit the Go official website to download and install the Go development environment.

Step 4: Install AIRec SDK for Go.

Obtain and Install AIRec SDK for Go of the latest version.

go get

AIRec-related protocol code is stored in the services/airec directory.

Step 5: Use AIRec SDK for Go

The following sample code describes how to use AIRec SDK for Go to create an instance:

package main

import (


func main() {

    var accessKeyID = "xxx"
    var accessKeySecret = "xxx"

    // Initialize configurations.
    endpoints.AddEndpointMapping("cn-hangzhou", "Airec", "")
    // Create a client.
    client, err := airec.NewClientWithAccessKey("cn-hangzhou", accessKeyID, accessKeySecret)
    if err ! = nil {

    // Create a request object.
    request := airec.CreateRecommendRequest()


    // Obtain responses.
    response, err := client.Recommend(request)
    if err ! = nil {