All Products
Search
Document Center

AI Guardrails:Delete faces

Last Updated:Mar 31, 2026

Use the Content Moderation Go SDK to delete one or more faces from a custom person's record.

All requests must go through the AI Guardrails API endpoints. For endpoint details, see Endpoints.

Prerequisites

Before you begin, ensure that you have:

  • Go dependencies installed using the required Go version. For installation instructions, see Installation

Important

Use the exact Go version specified in the Installation topic. Using a different version causes subsequent API calls to fail.

Parameters

ParameterTypeRequiredDescriptionExample
personIdStringYesThe ID of the custom person"person-001"
faceIdsArray of StringYesThe IDs of the faces to delete["face-id-1", "face-id-2"]

For the full parameter reference, see API operation for deleting faces.

Delete faces

The following example deletes faces from a custom person's record. The client is instantiated once and reused across requests to improve performance and avoid repeated connections.

package main

import (
    "encoding/json"
    "fmt"
    "os"
    "strconv"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/green"
)

func main() {
    // Instantiate the client once and reuse it to improve moderation performance.
    // Load credentials from environment variables to keep them out of your code.
    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
    }

    // personId: ID of the custom person (required)
    // faceIds: IDs of the faces to delete
    content, _ := json.Marshal(
        map[string]interface{}{
            "personId": "<your-person-id>",
            "faceIds":  []string{"<your-face-id>"},
        },
    )

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

    response, err := client.DeleteFaces(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 following placeholders with your actual values:

PlaceholderDescription
<your-person-id>ID of the custom person whose faces you want to delete
<your-face-id>ID of the face to delete. To delete multiple faces, add more entries to the faceIds array

Response

A successful request returns HTTP 200. The response body contains the operation result as a JSON string. For the response schema and error codes specific to this operation, see API operation for deleting faces.

What's next