[ PROMPT_NODE_24860 ]
quota
[ SKILL_DOCUMENTATION ]
# HeyGen 配额与积分
HeyGen 使用基于积分的系统进行视频生成。了解配额管理有助于防止视频生成请求失败。
## 查询剩余配额
### curl
bash
curl -X GET "https://api.heygen.com/v1/video_generate.quota"
-H "X-Api-Key: $HEYGEN_API_KEY"
### TypeScript
typescript
interface QuotaResponse {
error: null | string;
data: {
remaining_quota: number;
used_quota: number;
};
}
const response = await fetch("https://api.heygen.com/v1/video_generate.quota", {
headers: { "X-Api-Key": process.env.HEYGEN_API_KEY! },
});
const { data }: QuotaResponse = await response.json();
console.log(`Remaining credits: ${data.remaining_quota}`);
### Python
python
import requests
import os
response = requests.get(
"https://api.heygen.com/v1/video_generate.quota",
headers={"X-Api-Key": os.environ["HEYGEN_API_KEY"]}
)
data = response.json()["data"]
print(f"Remaining credits: {data['remaining_quota']}")
## 响应格式
{
"error": null,
"data": {
"remaining_quota": 450,
"used_quota": 50
}
}
## 积分消耗
不同的操作消耗不同数量的积分:
| 操作 | 积分消耗 | 备注 |
|-----------|-------------|-------|
| 标准视频 (1 分钟) | ~1 积分/分钟 | 因分辨率而异 |
| 720p 视频 | 基础费率 | 标准质量 |
| 1080p 视频 | ~1.5 倍基础费率 | 更高质量 |
| 视频翻译 | 不定 | 取决于视频时长 |
| 流式数字人 | 按会话计费 | 实时使用 |
## 生成前配额检查
在生成视频前,请务必确认配额充足:
typescript
async function generateVideoWithQuotaCheck(videoConfig: VideoConfig) {
// 先检查配额
const quotaResponse = await fetch(
"https://api.heygen.com/v1/video_generate.quota",
{ headers: { "X-Api-Key": process.env.HEYGEN_API_KEY! } }
);
const { data: quota } = await quotaResponse.json();
// 估算所需积分(粗略估算:1 积分/分钟)
const estimatedMinutes = videoConfig.estimatedDuration / 60;
const requiredCredits = Math.ceil(estimatedMinutes);
if (quota.remaining_quota < requiredCredits) {
throw new Error(
`Insufficient credits. Need ${requiredCredits}, have ${quota.remaining_quota}`
);
}
// 继续进行视频生成
return generateVideo(videoConfig);
}
## 配额管理最佳实践
### 1. 定期监控使用情况
typescript
async function