1. 获取 API Key
登录后在 控制台 → API 密钥 创建密钥。调用时通过 HTTP 头鉴权:
Authorization: Bearer sk-hy-xxxxxxxxxxxx
2. cURL 调用示例
curl https://api.tzsinen.cn/api/v1/chat/completions \
-H "Authorization: Bearer $HY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{ "role": "system", "content": "你是一个乐于助人的助手。" },
{ "role": "user", "content": "用一句话介绍 HoyooAPI。" }
],
"stream": false
}'
3. JavaScript (fetch) 示例
const res = await fetch("https://api.tzsinen.cn/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer " + HY_API_KEY,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "你好" }],
stream: false
})
});
const data = await res.json();
console.log(data.choices[0].message.content);
4. Python 示例
import requests
r = requests.post(
"https://api.tzsinen.cn/api/v1/chat/completions",
headers={"Authorization": "Bearer " + HY_API_KEY},
json={
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "你好"}],
"stream": False,
},
)
print(r.json()["choices"][0]["message"]["content"])