Initialization

更新时间:
复制 MD 格式

Set up a client to start making API requests with the AI Guardrails SDK for Go.

Prerequisites

Before you begin, ensure that you have:

Create a client

To make API requests, create a client instance with your region and AccessKey credentials.

Important

Store your AccessKey ID and AccessKey secret in environment variables rather than hardcoding them in your source code. Hardcoded credentials are a security risk and can be accidentally exposed in version control.

The following example creates a client for image, audio, video, and text moderation:

// Read credentials from environment variables
accessKeyID := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

// Create the client
client, _err := green.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret)
if _err != nil {
    panic(_err)
}

The supported regions are:

Region IDRegion name
cn-shanghaiChina (Shanghai)
cn-beijingChina (Beijing)
cn-shenzhenChina (Shenzhen)
ap-southeast-1Singapore

To use a different region, replace cn-shanghai with the target region ID. For example, to use China (Beijing):

client, _err := green.NewClientWithAccessKey("cn-beijing", accessKeyID, accessKeySecret)

What's next

With the client initialized, call the moderation APIs for your content type:

  • Image moderation

  • Audio moderation

  • Video moderation

  • Text moderation