Feature Overview
SDK/API Integration is a lightweight connection method provided by the LLM security module of WAF. With SDK/API Integration, you can directly call the LLM content security inspection capabilities of WAF to perform security moderation on LLM inputs and outputs without migrating your business domain to WAF.
Scenario
This document describes how to connect your LLM business to the WAF LLM security module through the SDK/API method. It applies to the following scenarios:
Your LLM business does not want to migrate all domains to WAF, but it needs to use the content security inspection capabilities of WAF.
You can quickly integrate the LLM content security moderation feature with minimal business changes.
The business architecture is not suitable for routing WAF traffic through domain connection methods.
You need to use the unique capabilities of the SDK/API connection method.
Note:
To use the LLM security feature through domain connection methods, see Traffic Onboarding. Prerequisites
You have purchased the Tencent Cloud WAF LLM Security add-on service. You can go to the LLM Security page and click Enable Now to view details and the ordering process. For detailed pricing, see Billing Overview. You have obtained your TencentCloud API access key (SecretId and SecretKey). If not, go to the API Key Management page to create one. Attention:
The user associated with the key must have the QcloudWAFFullAccess permission. Keep your security credentials safe to prevent leakage, which could compromise your property security. If your credentials have been leaked, disable them immediately.
Operation Step
Step 1: Adding an SDK Integration Application
1. Log in to the WAF console and click LLM Security in the left sidebar. 2. On the LLM Security page, click SDK Integration.
3. In the ①Add Application section on the SDK Integration page, enter the application name and other information, and click Add Application.
4. After the application is added successfully, the system will return the Service ID of the application.
Note:
The Service ID is a unique identifier automatically generated by the system. It is used to specify the protection policy during API calls. Record it properly, as it is required for subsequent API calls.
Step 2: Configuring Protection Policies
After adding an application, you need to configure an LLM security protection policy for the application, including compute consumption rules and custom protection rules.
1. On the SDK Integration list page, find the target application and click Security Configurations.
2. Configure compute consumption rules and custom protection rules based on your business requirements.
Note:
The protection policy configuration for the SDK/API connection method is basically the same as that for the domain connection method, but it does not include Session Identification settings and Condition settings (these two items apply only to the domain connection method). For detailed configuration instructions of the protection policy, see Compute Consumption Rules and Custom Protection Rules. Step 3: Installing and Integrating the SDK
After completing the console configuration, you need to integrate the WAF SDK into your business code and call the content security detection API.
Selecting a Region for Access
The following regions are currently supported for access. To reduce latency, we recommend that you use an access domain in the nearest region:
|
Nearest region access (recommended, non-financial regions only) | waf.tencentcloudapi.com
|
South China (Guangzhou) | waf.ap-guangzhou.tencentcloudapi.com
|
East China (Shanghai) | waf.ap-shanghai.tencentcloudapi.com
|
East China (Nanjing) | waf.ap-nanjing.tencentcloudapi.com
|
North China (Beijing) | waf.ap-beijing.tencentcloudapi.com
|
Southwest China (Chengdu) | waf.ap-chengdu.tencentcloudapi.com
|
Southwest China (Chongqing) | waf.ap-chongqing.tencentcloudapi.com
|
Note:
We recommend that you use an access domain in the nearest region. The system automatically resolves the domain to the nearest server based on the caller's location. For example, if a request is initiated in Guangzhou, the effect is the same as specifying waf.ap-guangzhou.tencentcloudapi.com.
For latency-sensitive services, we recommend that you specify a region-specific domain.
A domain is the access point of an API and does not represent the region where the product or API actually provides services.
Calling the API
The LLM security SDK/API Integration provides multiple core APIs:
|
| Large model content moderation API | Perform content security risk detection on the text/image content of user input or model output. Based on the configured protection rules, detect risks such as prompt injection, content security, and sensitive data, and return the detection results and risk classification tags. |
| Skill security detection upload API | Upload the Skill zip file to trigger asynchronous security detection. |
| Skill security detection result query API | Query Skill security detection results by file Hash. |
You can call the DescribeLLMContentSecCheck API to create a content detection task and perform content security moderation on user input or model output. For details, see Content Compliance Check. Skill security detection is an asynchronous detection. You can call the UploadSkillSecScan API to upload a Skill package and trigger detection. After the upload succeeds, the API returns the ContentHash of the file. Then use the ContentHash to call the DescribeSkillSecScanResult API to poll for detection results. The returned content includes the risk level (malicious / suspicious / benign), matched rule details, and disposal suggestions. For details, see Skill Security Detection. Step 4: Result verification
1. Call the SDK/API with test cases that include normal content and content expected to trigger risks.
2. Log in to the WAF console and check whether there are corresponding detection records and logs on the LLM Security page. 3. After the verification is passed, the SDK/API access is successful, and WAF will perform security detection on LLM content according to the configured protection policy.