Tencent - 미
Request URL
https://ai-gateway-intl.eo-edgefunctions7.com
Request method
POST
Request headers
Parameter name | Required | Type | Description |
OE-Key | Yes | string | Gateway API key |
OE-Gateway-Name | Yes | string | Gateway name |
OE-AI-Provider | Yes | string | AI service provider, fixed value: HunYuan |
OE-Gateway-Version | Yes | string | Gateway version, fixed value: 2 |
Authorization | No | string | Authentication Key of LLM Service Provider |
X-TC-Timestamp | Yes | string | Timestamp |
X-TC-Action | Yes | string | Fixed value: ChatCompletions |
X-TC-Version | No | string | Fixed value: 2023-09-01 |
Content-Type | Yes | string | Fixed value: application/json |
Request body
Parameter name | Required | Type | Description |
model | Yes | string | Model Name |
messages | Yes | array | Message list, each message includes role and content |
stream | Yes | boolean | Enable stream processing |
Request Body Example
{"model": "hunyuan-lite","messages": [{"role": "user","content": "1+1=?"}]"stream": true}
Sample response
The response format is JSON, and the specific content depends on the actual API return result.
Sample code for curl request
curl --location --request POST 'https://ai-gateway-intl.eo-edgefunctions7.com' \--header 'Authorization: xxxx' \--header 'X-TC-Timestamp: 1732178793' \--header 'X-TC-Action: ChatCompletions' \--header 'X-TC-Version: 2023-09-01' \--header 'X-TC-Language: zh-CN' \--header 'OE-Key: xxxx' \--header 'OE-Gateway-Name: xxxx' \--header 'OE-AI-Provider: hunyuan' \--header 'OE-Gateway-Version: 2' \--header 'Content-Type: application/json' \--data-raw '{"model": "hunyuan-lite","messages": [{"role": "user","content": "1+1=?"}]"stream": true}'
Notes
Note:
1. Please ensure all required parameters are correctly filled out.
2. Adjust the
Authorization
and X-TC-Timestamp
according to the actual situation.3. The
messages
array in the request body can contain multiple Message Objects, depending on business needs.4. The request parameters for the original HunYuan interface follow the Upper Camel Case Naming Convention. To unify the request parameters, it is now agreed that all parameters should follow the Lower Camel Case Naming Convention, and the Service Internal will process them uniformly.
References - HunYuan Large Model API Signature Algorithm
As the interface authentication for Tencent Cloud HunYuan Large Model is more stringent than for other large model providers, we now provide a Node version signature algorithm for developers. Details are as follows:
const CryptoJS = require("crypto-js");// SHA256 encryption functionfunction sha256(message, secret = "") {const hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, secret);return hmac.update(message).finalize();}// Compute the SHA256 hash value of messagesfunction getHash(message) {const hash = CryptoJS.SHA256(message);return hash.toString(CryptoJS.enc.Hex);}// Get date string from timestampfunction getDate(timestamp) {const date = new Date(timestamp * 1000);const year = date.getUTCFullYear();const month = ("0" + (date.getUTCMonth() + 1)).slice(-2);const day = ("0" + date.getUTCDate()).slice(-2);return `${year}-${month}-${day}`;}// Signature request functionfunction signRequest(secretId,secretKey,endpoint,service,action,timestamp,payload) {const date = getDate(timestamp);const hashedRequestPayload = getHash(JSON.stringify(payload));const httpRequestMethod = "POST";const canonicalUri = "/";const canonicalQueryString = "";const canonicalHeaders = `content-type:application/json\nhost:${endpoint}\nx-tc-action:${action.toLowerCase()}\n`;const signedHeaders = "content-type;host;x-tc-action";const canonicalRequest = `${httpRequestMethod}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${hashedRequestPayload}`;const algorithm = "TC3-HMAC-SHA256";const hashedCanonicalRequest = getHash(canonicalRequest);const credentialScope = `${date}/${service}/tc3_request`;const stringToSign = `${algorithm}\n${timestamp}\n${credentialScope}\n${hashedCanonicalRequest}`;const kDate = sha256(date, `TC3${secretKey}`);const kService = sha256(service, kDate);const kSigning = sha256("tc3_request", kService);const signature = sha256(stringToSign, kSigning, "hex");const authorization = `${algorithm} Credential=${secretId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;return authorization;}// Convert the key of the object to capitalized formfunction capitalizeKeys(obj) {return Object.keys(obj).reduce((acc, key) => {const capitalizedKey = key.charAt(0).toUpperCase() + key.slice(1);acc[capitalizedKey] = Array.isArray(obj[key])? obj[key].map(capitalizeKeys): typeof obj[key] === "object" && obj[key] !== null? capitalizeKeys(obj[key]): obj[key];return acc;}, {});}// Generate curl Commandfunction generateCurlCommand(endpoint,authorization,timestamp,action,version,payload) {const curlCommand ="curl -X POST " +"https://" +endpoint +'\n -H "Authorization: ' +authorization +'"' +'\n -H "Content-Type: application/json; charset=utf-8"' +'\n -H "Host: ' +endpoint +'"' +'\n -H "X-TC-Action: ' +action +'"' +'\n -H "X-TC-Timestamp: ' +timestamp.toString() +'"' +'\n -H "X-TC-Version: ' +version +'"' +"\n -d '" +JSON.stringify(payload) +"'";return curlCommand;}// Main Functionfunction main() {try {// 📢 Note: Replace the key here with your own Tencent Cloud console keyconst SECRET_ID = "SECRET_ID";const SECRET_KEY = "SECRET_KEY";// Define the relevant parameters of the APIconst endpoint = "hunyuan.tencentcloudapi.com";const service = "hunyuan";const action = "ChatCompletions";const version = "2023-09-01";const timestamp = parseInt(Date.now() / 1000);// 📢 Note: Replace the request parameters here with your actual request parameter valuesconst reqBody = {model: "hunyuan-lite",messages: [{role: "user",content: "1+1=?",},]};// Retrieve and process the request bodyconst body = capitalizeKeys(JSON.parse(pm.request.body.toJSON().raw));console.log("body:", JSON.stringify(body));// Signature requestconst authorization = signRequest(SECRET_ID,SECRET_KEY,endpoint,service,action,timestamp,body);// Generate and print curl commandconst curlCommand = generateCurlCommand(endpoint,authorization,timestamp,action,version,body);console.log("curl:", curlCommand);} catch (error) {console.error("Error:", error);}}main();