All Products
Search
Document Center

AI Guardrails:Query information about face images

Last Updated:Mar 31, 2026

Retrieves stored face metadata—face IDs and image file paths—for a given person and set of face IDs, using the Go SDK.

For the full parameter reference, see API operation for querying information about face images.

Usage notes

Use the AI Guardrails API endpoints when calling this SDK. For endpoint details, see Endpoint.

Prerequisites

Before you begin, ensure that you have:

  • Go dependencies installed using the required Go version described in Installation

Using an unsupported Go version causes subsequent operation calls to fail.

Query face image information

Request parameters

All parameters in the request body are required.

ParameterTypeRequiredDescription
personIdstringYesThe ID of the custom person to query
faceIdsarray of stringsYesThe IDs of the faces to query

Example

The following example queries face information for a person by specifying a person ID and two face IDs. Reuse the client instance across requests to improve moderation performance and avoid repeated connection overhead.

package main

import (
    "encoding/json"
    "fmt"
    "os"
    "strconv"

    "github.com/aliyun/alibaba-cloud-sdk-go/services/green"
)

func main() {
    // Initialize the client once and reuse it across requests.
    // Read credentials from environment variables to avoid hardcoding sensitive values.
    client, err := green.NewClientWithAccessKey(
        "cn-shanghai",
        os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
        os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
    )
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Specify the person ID and the face IDs to query.
    content, _ := json.Marshal(
        map[string]interface{}{
            "personId": "<your-person-id>",
            "faceIds":  []string{"<face-id-1>", "<face-id-2>"},
        },
    )

    request := green.CreateGetFacesRequest()
    request.SetContent(content)

    response, err := client.GetFaces(request)
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    if response.GetHttpStatus() != 200 {
        fmt.Println("Request failed. HTTP status code: " + strconv.Itoa(response.GetHttpStatus()))
        return
    }

    fmt.Println(response.GetHttpContentString())
}

Replace the placeholders before running the example:

PlaceholderDescriptionExample
<your-person-id>The ID of the custom personperson_001
<face-id-1>, <face-id-2>The IDs of the faces to queryface_abc, face_xyz

Response

A successful request returns HTTP status code 200. The response body contains the face IDs and image file paths associated with the specified person. For the complete response schema, see API operation for querying information about face images.