Skip to content

API Key Environment Variable Configuration ​

Updated

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.

bash
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.

bash
python3 --version
python3 -m json.tool request.json > /dev/null

Running Your First Request ​

The following is an MPS image request example. Use CreateAigcVideoTask for video and CreateAigcAudioTask for music.

bash
python3 tencent-api.py mps CreateAigcImageTask request.json > accepted.json

If you use VOD, use the VOD model page's JSON and specify SubAppId as your actual Application ID.

bash
python3 tencent-api.py vod CreateAigcImageTask request.json > accepted.json

Each 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.

bash
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.json

For 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 ​

PathCompletion CheckResult Storage
MPS AIGCIf it is DONE, check the result; if it is FAIL, check the failure reasonDownload before the temporary URL expires, or use StoreCosParam to save it as COS
VOD AIGCCheck FINISH and ErrCode=0 togetherTemporary 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.

bash
export API_TOKEN='<VOD API Token>'
curl https://mmu.vod-qcloud.com/v1/models \
  -H "Authorization: Bearer ${API_TOKEN}"

Troubleshooting ​

SymptomItems to Check
AuthFailureKey, CAM permissions, local time, API path
InvalidParameterFields by model·version, JSON type, input URL
RequestLimitExceededReduce the call rate and retry after waiting
Timeout before receiving the generation responseCheck the submission status and logs to avoid duplicate generation

Built with VitePress · Deployed on Tencent EdgeOne Pages