Plattform für Grenzgänger
  • AI 게이트웨이
    • 제품 소개
    • 빠른 시작
    • 개발 가이드
      • V1
      • V2
        • 개요
        • 공개 요청 헤더 소개
        • Tencent - 미
        • 바이두 - 천범
        • 바이트-콩밥
        • 알리-통 의
        • 문샷 - 키미
        • 미니 맥스 (Minimax)
        • 개방형 AI
        • 쌍둥이 자리
    • 자주 묻는 질문
    • 제품 동향
이 페이지는 현재 영어로만 제공되며 한국어 버전은 곧 제공될 예정입니다. 기다려 주셔서 감사드립니다.

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 function
function sha256(message, secret = "") {
const hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, secret);
return hmac.update(message).finalize();
}

// Compute the SHA256 hash value of messages
function getHash(message) {
const hash = CryptoJS.SHA256(message);
return hash.toString(CryptoJS.enc.Hex);
}

// Get date string from timestamp
function 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 function
function 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 form
function 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 Command
function 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 Function
function main() {
try {
// 📢 Note: Replace the key here with your own Tencent Cloud console key
const SECRET_ID = "SECRET_ID";
const SECRET_KEY = "SECRET_KEY";

// Define the relevant parameters of the API
const 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 values
const reqBody = {
model: "hunyuan-lite",
messages: [
{
role: "user",
content: "1+1=?",
},
]
};
// Retrieve and process the request body
const body = capitalizeKeys(JSON.parse(pm.request.body.toJSON().raw));

console.log("body:", JSON.stringify(body));

// Signature request
const authorization = signRequest(
SECRET_ID,
SECRET_KEY,
endpoint,
service,
action,
timestamp,
body
);

// Generate and print curl command
const curlCommand = generateCurlCommand(
endpoint,
authorization,
timestamp,
action,
version,
body
);
console.log("curl:", curlCommand);
} catch (error) {
console.error("Error:", error);
}
}

main();