Initialize the AI Guardrails SDK for .NET by creating a client instance before making API requests.
Prerequisites
Before you begin, ensure that you have:
An Alibaba Cloud account with an AccessKey pair. To get one, see Obtain an AccessKey pair
The AI Guardrails SDK for .NET installed in your project
Set up credentials
Store your AccessKey ID and AccessKey secret as environment variables to keep credentials out of your source code.
On Linux or macOS:
export ALIBABA_CLOUD_ACCESS_KEY_ID=<your-access-key-id>
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<your-access-key-secret>On Windows:
set ALIBABA_CLOUD_ACCESS_KEY_ID=<your-access-key-id>
set ALIBABA_CLOUD_ACCESS_KEY_SECRET=<your-access-key-secret>Replace <your-access-key-id> and <your-access-key-secret> with the values from your Alibaba Cloud account.
Create a client instance
The following code creates a client instance for moderating images, audio, videos, and text. It reads credentials from environment variables and targets the China (Shanghai) region.
// Read credentials from environment variables
string accessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
string accessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
DefaultProfile profile = DefaultProfile.GetProfile(
"cn-shanghai",
accessKeyId,
accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);To use a different region, replace cn-shanghai with the target region ID. The following regions are supported:
| Region ID | Region name |
|---|---|
cn-shanghai | China (Shanghai) |
cn-beijing | China (Beijing) |
cn-shenzhen | China (Shenzhen) |
ap-southeast-1 | Singapore |
For the full list of endpoints, see Endpoints.