API Key Environment Variable Configuration
This document describes the configuration for the TC3 call script on the Wiki. TENCENT_SECRET_ID and TENCENT_SECRET_KEY are Tencent Cloud account keys, which are different from the API_TOKEN of the text gateway.
Account Keys and Region
Run it in a macOS·Linux terminal. Enter each export on a separate line.
export TENCENT_SECRET_ID='<SecretId>'
export TENCENT_SECRET_KEY='<SecretKey>'
export TENCENT_REGION='ap-singapore'The environment variable names used by SDK or tccli may differ. This script reads the three names above. Select the API path and region based on the API Reference of the service you use.
Preparing the Call Script
Install Python 3 and save tencent-api.py to your working folder. No additional packages are required. Save the request example from the model page as request.json.
python3 --version
python3 -m json.tool request.json > /dev/nullRunning Your First Request
The following is an MPS image request example. Use CreateAigcVideoTask for video and CreateAigcAudioTask for music.
python3 tencent-api.py mps CreateAigcImageTask request.json > accepted.jsonIf you use VOD, use the VOD model page's JSON and specify SubAppId as your actual Application ID.
python3 tencent-api.py vod CreateAigcImageTask request.json > accepted.jsonEach of the two commands submits a new generation task. Run only one of the paths. The signature is calculated automatically from the timestamp and body at execution time.
Querying Results by TaskId
Use the Response.TaskId from the submission response to build a query JSON.
python3 - <<'PYTHON'
import json
with open('accepted.json') as f:
response = json.load(f)['Response']
if 'Error' in response:
raise SystemExit(response['Error'])
with open('query.json', 'w') as f:
json.dump({'TaskId': response['TaskId']}, f)
PYTHON
python3 tencent-api.py mps DescribeAigcImageTask query.jsonFor MPS, use DescribeAigcVideoTask for video and DescribeAigcAudioTask for music. For VOD, add to query.json the same SubAppId as in the generation request, and then query with vod DescribeTaskDetail.
Completion Check and File Storage
| Path | Completion Check | Result Storage |
|---|---|---|
| MPS AIGC | If it is DONE, check the result; if it is FAIL, check the failure reason | Download before the temporary URL expires, or use StoreCosParam to save it as COS |
| VOD AIGC | Check FINISH and ErrCode=0 together | Temporary is a temporary URL, Permanent is the VOD FileId |
If it is still being processed, query again later with the same TaskId. Sending the generation request again just because a query is slow may create a separate task. For the actual result fields, see the response examples in MPS·VOD.
Text Model Authentication
Configure the token issued in VOD Text separately.
export API_TOKEN='<VOD API Token>'
curl https://mmu.vod-qcloud.com/v1/models \
-H "Authorization: Bearer ${API_TOKEN}"Troubleshooting
| Symptom | Items to Check |
|---|---|
AuthFailure | Key, CAM permissions, local time, API path |
InvalidParameter | Fields by model·version, JSON type, input URL |
RequestLimitExceeded | Reduce the call rate and retry after waiting |
| Timeout before receiving the generation response | Check the submission status and logs to avoid duplicate generation |