Set up a client to start making API requests with the AI Guardrails SDK for Go.
Prerequisites
Before you begin, ensure that you have:
An Alibaba Cloud account with an AccessKey pair. To create one, see Obtain an AccessKey pair.
A supported region for your use case. For the full list, see Endpoints.
Create a client
To make API requests, create a client instance with your region and AccessKey credentials.
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 ID | Region name |
|---|---|
cn-shanghai | China (Shanghai) |
cn-beijing | China (Beijing) |
cn-shenzhen | China (Shenzhen) |
ap-southeast-1 | Singapore |
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